Waldek Hebisch wrote:
I do not understand what is your point here. Do you argue "in abstract" or maybe you have some concrete proposal what to change in GPC?
Based on Frank's and Peter's comments, I propose the following:
1. Predefine 2 pseudo-schema types to define signed and unsigned integral types:
IntegerWithBits (n) CardinalWIthBits (n)
where n is a compile-time constant expression.
Examples:
Type Int16 = IntegerWithBits( 16); {defines an integer type in the range -32768 .. 32767} Word32 = CardinalWIthBits( 32); {defines a cardinal type in the range 0..$FFFFFFFF} RealInt = IntegerWithBits( BitSizeOf( Real)); {defines an integer type with the same size as a Real}
Note that BooleanWithBits is not needed, as a Boolean has only one bit of data (also see below).
2. Deprecate the Size attribute (issue a warning that it will be removed).
Example:
Type Int64 = Integer attribute( size = 64); {warning: use of the Size attribute is deprecated; this will be an error in a future compiler release}
3. Optionally, implement a Bitsize attribute for all types except arrays. The Bitsize attribute will add pad bits if needed and it will check that the type fits in the given number of bits.
Examples:
Type Int16 = Integer attribute( bitsize = 16); {error on most platforms: the referenced `Integer' type doesn't fit into 16 bits} Bool32 = Boolean attribute( bitsize = 32); {defines a 32-bit Boolean} Sex8 = ( female, male) attribute ( bitsize = 8); {defines an 8-bit enumerated type} Style8 = set of (plain, boldface, italic, underline) attribute( bitsize = 8); {error: the `Style8 ' set type doesn't fit into 8 bits} PaddedCharsArray = array[ 0..2] of Char attribute( bitsize = 32); {not allowed} PaddedCharsRecord = record c: array[ 0..2] of Char end attribute( bitsize = 32); {make sure the record is 32-bit aligned} BitsRec2 = record b1,b2: 0..1 attribute( bitsize = 16) end; {currently not allowed, but useful}
I think, source code incompatibilities will be bearable, because the compiler will issue warnings where current source code has to be changed. The only remaining issue is that n-bit-padded booleans can no longer be defined if (3) is not implemented.
Regards,
Adriaan van Os