Frank Heckenbach wrote:
Adriaan van Os wrote:
So, all of these type casts work, except the value type cast i:=word32( 'abcd'). This can be worked around by:
- using a variable type cast instead of a value type cast, e.g.
fourcharcode( i ):= 'abcd'
- declaring a typed constant for the fourcharcode (which is not a bad
idea anyway), e.g. i:=word32( k1)
Unfortunately, both aren't suitable for case constants, as in Peter's example. (Though I don't know if they're frequently used that way.)
To speak for myself, no. I looked into a typical Mac OS program with 300.000 lines of code. It had 443 case statements, but none of them used FourCharCodes as case constants.
It would be nice if GPC were to allow i:=word32( 'abcd') also (e.g. in --macpascal mode), but this is not a necessity.
This would have to make an implicit decision about endianness,
Can't the compiler just look at __BYTES_BIG_ENDIAN__ and __BYTES_LITTLE_ENDIAN__ ?
and it might be problematic if in the future GPC will work with Unicode (or any other >8 bit charset), since 4 characters won't fit in a 32 bit integer.
That would give rise to some very interesting problems anyway. For binary compatibility with existing API's (on many platforms), we will always need some 8-bit char type. Then, how do you indicate that a string constant is composed of either 8-bit or (e.g.) 16-bit characters ?
Changing FourCharCode = UInt32 is probably better since the concept behind it is as a fixed size low cost use, and it is essentially never used as a string as such.
I am not convinced that changing FourCharCode to UInt32 is a good idea.
Ordinal constants are the only allowed case constants. So if that's a serious concern, I think there's generally no other way.
I believe the limitation is acceptable, at least not serious enough to come up with tricks (that make source code more obscure). The case statement can be rewritten to an if statement.
Regards,
Adriaan van Os