bitpacked record interpreted incorrectly with i386
Original Reporter info from Mantis: sethdgrover@gmail.com
-
Reporter name: Seth Grover
Original Reporter info from Mantis: sethdgrover@gmail.com
- Reporter name: Seth Grover
Description:
I have the following types defined:
====================================================
type
TPad1 = 0..65535; // 16 bits padding
TLevel1 = 0..63; // 6 bits
TLevel2 = 0..1023; // 10 bits
TLevel3 = 0..16777215; // 24 bits
TLevel4 = 0..255; // 8 bits
TLevelsRec = bitpacked record
level4 : TLevel4;
level3 : TLevel3;
level2 : TLevel2;
level1 : TLevel1;
pad : TPad1; // padding to make record size 64 bits
end;
====================================================
When I do the following:
FillChar(id, sizeof(id), 0);
TLevelsRec(id).level1 := 1;
TLevelsRec(id).level2 := 2;
TLevelsRec(id).level3 := 3;
TLevelsRec(id).level4 := 4;
and then do something that accesses the level3 field, it is not read from the bitpacked record correctly. This appears to only happen when compiling for 32-bit (compiling for x86_64 does not reproduce the problem).
See the attached sample program which illustrates the problem.
Mantis conversion info:
- Mantis ID: 17715
- OS: Linux
- OS Build: Ubuntu 10.04
- Build: 2.4.2-rc1
- Platform: i386
- Version: 2.4.2
- Fixed in version: 2.6.0
- Fixed in revision: 16227 (#9ab05031)