A question on bit-field widths.

diamond@tkovoa diamond at tkou02.enet.dec.com
Wed Dec 19 12:31:09 AEST 1990


Subject: Re: A question on bit-field widths.
In article <3028 at lupine.NCD.COM> rfg at lupine.ncd.com (Ron Guilmette) writes:
>I am posting this question to both comp.std.c and comp.std.c++ because
>the question arises for both languages.
And the only way I can follow-up is by mailing to
comp-std-c at ucbvax.berkeley.edu, sigh.
 
>Given a machine on which 'long int' is 32 bits and `short int' is 16 bits,
>what should the following program print?
>struct S1 { long  field:33;  };
>struct S2 { short field1:17; ... };
>...
>  printf ("sizeof (struct S1) = %d\n", sizeof (struct S1));
>  ...
 
Lots of possibilities.  I have the impression that a char could be 40 bits,
so that sizeof(long int) and sizeof(short int) could both be 1.
 
>Should this program even be allowed to compile without errors?
 
Depending on the implementation, it should be allowed, as above.
However, if a char is 16 or 8 or some other expected number of bits, and
sizeof(long int) and sizeof(short int) really occupy exactly 32 and 16
bits, then the second Constraint in section 3.5.2.1 is violated and a
diagnostic is required.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.



More information about the Comp.std.c mailing list