Xref: utzoo comp.std.c:4040 comp.std.c++:493 Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ames!amdahl!pyramid!decwrl!infopiz!lupine!lupine.ncd.com From: rfg@lupine.ncd.com (Ron Guilmette) Newsgroups: comp.std.c,comp.std.c++ Subject: A question on bit-field widths. Message-ID: <3028@lupine.NCD.COM> Date: 17 Dec 90 22:10:36 GMT Sender: rfg@NCD.COM Followup-To: comp.std.c Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 44 I am posting this question to both comp.std.c and comp.std.c++ because the question arises for both languages. Given a machine on which 'long int' is 32 bits and `short int' is 16 bits, what should the following program print? Should this program even be allowed to compile without errors? struct S1 { long field:33; }; struct S2 { short field1:17; short field2:17; int field3; short field4:17; }; extern printf (const char *, ...); struct S1 s1; struct S2 s2; int main () { printf ("sizeof (struct S1) = %d\n", sizeof (struct S1)); printf ("sizeof (struct S2) = %d\n", sizeof (struct S2)); s2.field1 = 0x3FFFF; s2.field2 = 0x3FFFF; s2.field4 = 0x3FFFF; printf ("field1 = %d, field2 = %d, field3 = %d\n", s2.field1, s2.field2, s2.field3); return 0; } As usual, it would be helpful if someone could point me at the appropriate parts of the C standard (or Annotated C++ Reference Manual) where such questions are answered. Thanks.