[fpc-devel] "Ordinal expression expected" awkwardness
Sven Barth
pascaldragon at googlemail.com
Thu Jul 20 07:58:50 CEST 2023
J. Gareth Moreton via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am
Mi., 19. Juli 2023, 19:53:
> Hi everyone,
>
> So I've come across a bit of awkwardness with the compiler. I'm not
> sure if it's a well-defined rule that I've overlooked, but in a
> for-loop, you can't use a 64-bit control variable when compiling for
> i386-win32 (and presumably other 32-bit platforms), but you can under
> x86_64-win64. In my case, the upper bound is a 64-bit variable (of type
> TConstExprInt... a record type in the compiler source), so downsizing is
> not ideal (although I will likely put in code that will error out if the
> upper bound is too large due to the risk of an malicious inputs causing
> said bound to equal 2^63 - 1 or 2^64 - 1).
>
> My example aside, should it be that there's a situation where pure Free
> Pascal code can build on a 64-bit compiler but not a 32-bit compiler?
> IFpermitting 64-bit control variables is too difficult for 32-bit
> systems, should they be forbidden entirely or at least throw a warning?
>
> Kit
>
> P.S. As the title implies, trying to use a QWord or Int64 as a for-loop
> control variable under i386-win32 causes an "Ordinal expression
> expected" error, but compiles without incident on x86_64-win64.
>
It is indeed by design that not every integer type is a suitable index
variable for a for-loop. In this case that a 64-bit variable can't be used
on a platform with less than 64-bit width. The same is probably also true
for 32-bit variables on platforms with less width (e.g. i8086, AVR, Z80).
Cross platform code needs to cater for this accordingly.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20230720/3d7172b8/attachment.htm>
More information about the fpc-devel
mailing list