c++ - sizeof pragma packed bitfield struct array -
I use Visual Studio 2013 for an x64 system. I have the following structure:
#pragma pack (1) Structure timestrut {int miliseconds: 10; BYTE seconds: 6; BYTE minutes: 6; BYTE hours: 5; Byte Day: 5; }; #pragma pack () and an array:
timestred stereo [10]; When I use the sizeAuf (stArray); I get 80 as a retell instead of 40.
I have to know what the problem is that the compiler does not pack properly or if the sizeof bitfile does not consider the actual size.
Thanks
For more clarification on how MSVC bitfelt behaves, see .
This implementation is dependent on how bitfields are packed and ordered, so you should know what the layout is different from what is expected, and will depend on the particular compiler you are using.
sizeof () gives you the shape of the structure regardless of its members, so this is bitfile packing which is different from your expectations.
You can probably guess about the layout or use this code to search for layouts:
struct timeline a; Unsigned four * b = (unsigned char *) and; A.milliseconds = 1; A.seconds = 2; A.minutes = 3; A.hour = 3; A.day = 4; For (size_t i = 0; i It appears that the structure is allocated for the whole int for 1. If you use int or unsigned int for all areas, you will be able to pack it tightly with the MSVC compiler, and this structure will take 4 bytes: int milliseconds: 10; Members, and the remaining 3 bytes are packed individually, assigning one BYTE to each member, but do not combine bits from different allocated units.
Struct timestread {int miliseconds: 10; Int. Seconds: 6; Int Minute: 6; Full hour: 5; Int day: 5; };
Comments
Post a Comment