[fpc-devel] size of bitpacked records ?

Gennadiy Poryev core at barvinok.net
Thu Jan 30 09:36:01 CET 2014


Hi,

I need to specify 7-byte unsigned integer field in packed structure. To 
my surprise, this turned out to be not an easy thing to do across 
win32/win64 bit codebase.

Here's the test code

|program structtest;||
||
||TYPE Struct1Byte = bitpacked record||
||      Field : $00..$FF;||
||     end;||
||
||     Struct2Byte = bitpacked record||
||      Field : $00..$FFFF;||
||     end;||
||
||     Struct3Byte = bitpacked record||
||      Field : $00..$FFFFFF;||
||     end;||
||
||     Struct4Byte = bitpacked record||
||      Field : $00..$FFFFFFFF;||
||     end;||
||
||     Struct5Byte = bitpacked record||
||      Field : $00..$FFFFFFFFFF;||
||     end;||
||
||     Struct6Byte = bitpacked record||
||      Field : $00..$FFFFFFFFFFFF;||
||     end;||
||
||     Struct7Byte = bitpacked record||
||      Field : $00..$FFFFFFFFFFFFFF;||
||     end;||
||
||begin||
|| Writeln('SizeOf(Struct1Byte) = ',SizeOf(Struct1Byte));||
|| Writeln('SizeOf(Struct2Byte) = ',SizeOf(Struct2Byte));||
|| Writeln('SizeOf(Struct3Byte) = ',SizeOf(Struct3Byte));||
|| Writeln('SizeOf(Struct4Byte) = ',SizeOf(Struct4Byte));||
|| Writeln('SizeOf(Struct5Byte) = ',SizeOf(Struct5Byte));||
|| Writeln('SizeOf(Struct6Byte) = ',SizeOf(Struct6Byte));||
|| Writeln('SizeOf(Struct7Byte) = ',SizeOf(Struct7Byte));||
||end.||
|
Here's what it produces when built for Win32

SizeOf(Struct1Byte) = 1
SizeOf(Struct2Byte) = 2
SizeOf(Struct3Byte) = 3
SizeOf(Struct4Byte) = 4
*SizeOf(Struct5Byte) = 8**
**SizeOf(Struct6Byte) = 8**
**SizeOf(Struct7Byte) = 8**
*
Here's what for Win64

SizeOf(Struct1Byte) = 1
SizeOf(Struct2Byte) = 2
SizeOf(Struct3Byte) = 3
SizeOf(Struct4Byte) = 4
*SizeOf(Struct5Byte) = 5**
**SizeOf(Struct6Byte) = 6**
**SizeOf(Struct7Byte) = 7**
*
Am I misusing bitpacked records somehow, or does this qualify as a bug?

// Gennadiy.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140130/a3351f0d/attachment.html>


More information about the fpc-devel mailing list