Allow bit-fields in unions.

All versions of standard C allow this, but ORCA/C previously did not.
This commit is contained in:
Stephen Heumann 2021-10-18 21:48:18 -05:00
parent 692ebaba85
commit f567d60429
3 changed files with 15 additions and 6 deletions

View File

@ -2795,10 +2795,12 @@ var
fl := variable;
end; {if}
end; {if}
if kind = unionType then begin
disp := 0;
bitdisp := 0;
end; {if}
if token.kind = colonch then {handle a bit field}
begin
if kind = unionType then
Error(56);
NextToken;
Expression(arrayExpression,[commach,semicolonch]);
if (expressionValue >= maxBitField) or (expressionValue < 0) then
@ -2823,6 +2825,9 @@ var
else
tPtr := typeSpec;
bitdisp := bitdisp+long(expressionValue).lsw;
if kind = unionType then
if ((bitDisp+7) div 8) > maxDisp then
maxDisp := ((bitDisp+7) div 8);
if (tPtr^.kind <> scalarType)
or not (tPtr^.baseType in
[cgByte,cgUByte,cgWord,cgUWord,cgLong,cgULong])
@ -2836,9 +2841,7 @@ var
if bitdisp <> 0 then begin
disp := disp+((bitDisp+7) div 8);
bitdisp := 0;
end {if}
else if kind = unionType then
disp := 0;
end; {if}
variable^.disp := disp;
variable^.bitdisp := bitdisp;
variable^.bitsize := 0;

View File

@ -627,7 +627,7 @@ if list or (numErr <> 0) then begin
53: msg := @'the structure or union has already been defined';
54: msg := @'bit fields must be less than 32 bits wide';
55: msg := @'a value cannot be zero bits wide';
56: msg := @'bit fields in unions are not supported by ORCA/C';
{56: msg := @'bit fields in unions are not supported by ORCA/C';}
57: msg := @'compiler error';
58: msg := @'implementation restriction: too many local labels';
59: msg := @'file name expected';

View File

@ -206,6 +206,10 @@ p. 277
The type "long double" now specifies a number in the SANE extended format.
p. 286
Unions may now contain bit fields.
p. 289
Unions can be initialized by a brace-enclosed expression giving the initializer value for the first element of the union, or by an expression of the appropriate union type. The non-standard construct of initializing the first element of a union with a non-brace-enclosed initializer is no longer supported. The supported alternative is simply to enclose the initializer in braces, e.g.
@ -1370,6 +1374,8 @@ int foo(int[42]);
167. If an array with automatic storage duration was initialized from a string literal containing an embedded null byte (e.g. char s[] = "a\0b"), characters after the null byte would not be properly initialized.
168. Unions may now contain bit-fields, as specified in the C standards.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.