Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2023-07

"Ordinal expression expected" awkwardness

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

J. Gareth Moreton

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.

Reply by email

Sven Barth
to J. Gareth Moreton

J. Gareth Moreton via fpc-devel schrieb am
Mi., 19. Juli 2023, 19:53:

Show quoted text 23 lines
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

Reply by email

Bart
to Sven Barth
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).

The errormessage suggest that a 64-bit integer variable is not an ordinal in a 32-bit environment, which is a bit odd. The first time I encountered this, I stared at it wondering what went wrong. (Once you know, it's easy...)

Bart

Reply by email