Subj : Re: bit field bug? To : borland.public.cpp.borlandcpp From : =?ISO-8859-1?Q?Mikko_Syrj=E4?= Date : Wed Nov 19 2003 12:37 pm Jeff wrote: > I am upgrading an old app from Borland C++ 5.01a to the latest MS Visual > Studio C++. The app uses bitfields in data structures and I am seeing a > problem where it looks like the MS version of the data structure is correct > in size, but the Borland C++ version is larger by 1 byte than it should be. > Is there a bug in BC++ 5.01a in the bit field assignment and layout? > > Any info would be greatly appreciated... also any pointer to documents on > this, since I will need to account for the difference in size of the > bitfields during client server data transfer for backward compatibility in > my app. > I used to work with bc++ 5.02 some years ago and there was indeed something strange in bitfields. Compile and run following code: ------------------------------------------------------------------ #include // old header typedef struct { unsigned level:6; unsigned :1; // unnamed bit field unsigned complex:1; unsigned type:7; unsigned deleted:1; unsigned short words; unsigned long xlow; unsigned long ylow; unsigned long zlow; unsigned long xhigh; unsigned long yhigh; unsigned long zhigh; } Elm_hdr_old; // new header typedef struct { unsigned level:6; unsigned foo:1; // named bit field unsigned complex:1; unsigned type:7; unsigned deleted:1; unsigned short words; unsigned long xlow; unsigned long ylow; unsigned long zlow; unsigned long xhigh; unsigned long yhigh; unsigned long zhigh; } Elm_hdr_new; int main() { cout << "Elm_hdr_old: " << sizeof(Elm_hdr_old) << "\n" << "Elm_hdr_new: " << sizeof(Elm_hdr_new) << "\n"; return 0; } ------------------------------------------------------------------ and the program output is: Elm_hdr_old: 30 Elm_hdr_new: 28 I'm not sure if this has something to do with your problem, but you should check those bitfield names. Mikko .