Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - I've got a struct with a 12 bit variable and four 1 bit variables,
#pragma pack(1) struct pvlist { Uword polygon_id : 12; Uchar vtxflag_0 : 1; Uchar vtxflag_1 : 1; Uchar vtxflag_2 : 1; Uchar vtxflag_3 : 1; }; #pragma pack() The total number of bits there is 16, of course, so it should fit in two bytes. However, DMC is making it 3 bytes in size. (If I omit the pragma pack stuff, it makes it 4 bytes instead) I tried changing 'Uword polygon_id : 12' to 'Uchar polygon_id : 12' to see if that worked, but it didn't. The compiler complained that "12 exceeds maximum bit field width of 8 bits." Rearranging the variables in the struct doesn't make it smaller either. Oddly, if I omit the type from polygon_id's declaration entirely, the struct becomes 5 bytes long. I wouldn't even have expected that to compile, heh. Is this a compiler bug? The reason I'm asking is because there's some asm code which depends on this being 2 bytes in size. If this isn't a compiler bug, I'll "fix" the code of course, but it seems to me that DMC is wasting a byte. Or possibly I shouldn't be using pragma pack(1), if there's some way to tell it not to try to align anything in the struct on any boundaries at all (if that's the problem). -SL Apr 24 2005
SL wrote:#pragma pack(1) struct pvlist { Uword polygon_id : 12; Uchar vtxflag_0 : 1; Uchar vtxflag_1 : 1; Uchar vtxflag_2 : 1; Uchar vtxflag_3 : 1; }; #pragma pack() The total number of bits there is 16, of course, so it should fit in two bytes. However, DMC is making it 3 bytes in size. (If I omit the pragma pack stuff, it makes it 4 bytes instead) Apr 24 2005
Bertel Brander wrote:This one print 2: Apr 24 2005
|