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.)
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, 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.
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.
Frank