Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!bionet!agate!ucbvax!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com ("diamond@tkovoa") Newsgroups: comp.std.c Subject: Re: A question on bit-field widths. Message-ID: <9012190130.AA26473@decpa.pa.dec.com> Date: 19 Dec 90 01:31:09 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 28 Subject: Re: A question on bit-field widths. In article <3028@lupine.NCD.COM> rfg@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@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@tkov50.enet.dec.com If this were the company's opinion, I wouldn't be allowed to post it.