Hello,
I am getting a different size than expected in bitpacked records that contain enumerated types. Consider the following sample program:
{$APPTYPE CONSOLE}
{$ifdef FPC}
{$MODESWITCH NESTEDCOMMENTS OFF}
{$endif}
{$MINENUMSIZE 4}
{$TYPEDADDRESS ON}
{$LONGSTRINGS OFF}
program _BitpEnumeration;
type
_1bit = 0 .. $1;
_30bits = 0 .. $3FFFFFFF;
_31bits = 0 .. $7FFFFFFF;
type
{ _THREAD_UMS_INFORMATION_COMMAND }
PTHREAD_UMS_INFORMATION_COMMAND = ^TTHREAD_UMS_INFORMATION_COMMAND;
TTHREAD_UMS_INFORMATION_COMMAND =
(
{ 0 0 } UmsInformationCommandInvalid,
{ 1 1 } UmsInformationCommandAttach,
{ 2 2 } UmsInformationCommandDetach,
{ 3 3 } UmsInformationCommandQuery
);
type
PTHREAD_UMS_INFORMATION = ^TTHREAD_UMS_INFORMATION;
TTHREAD_UMS_INFORMATION = {$ifdef FPC} bitpacked {$endif} record
Command : TTHREAD_UMS_INFORMATION_COMMAND; { 4 }
CompletionList : pointer; { 4 }
UmsContext : pointer; { 4 }
case integer of
1 : (
Flags : DWORD; { 4 }
);
{$ifdef FPC}
2 : (
IsUmsSchedulerThread : _1bit;
IsUmsWorkerThread : _1bit;
SpareBits : _30bits;
);
{$endif}
end;
type
PTHREAD_UMS_INFORMATION2 = ^TTHREAD_UMS_INFORMATION2;
TTHREAD_UMS_INFORMATION2 = record
Command : TTHREAD_UMS_INFORMATION_COMMAND; { 4 }
CompletionList : pointer; { 4 }
UmsContext : pointer; { 4 }
case integer of
1 : (
Flags : DWORD; { 4 }
);
{$ifdef FPC}
2 : (
BitFlags : bitpacked record
IsUmsSchedulerThread : _1bit;
IsUmsWorkerThread : _1bit;
SpareBits : _30bits;
end;
);
{$endif}
end;
begin
writeln;
writeln;
writeln(' sizeof TTHREAD_UMS_INFORMATION : ', sizeof(TTHREAD_UMS_INFORMATION));
writeln(' sizeof TTHREAD_UMS_INFORMATION2 : ', sizeof(TTHREAD_UMS_INFORMATION2));
writeln;
writeln;
writeln('press ENTER/RETURN to end this program');
readln;
end.
The output size of the first structure is 13 instead of the expected size of 16.
Changing the structure definition to exclude the enumeration from the bitpacked scope results in the expected size but this requires naming the group of bits, doing that makes it different than the original C definition.
Is there a way to have the "Command" enumerated field occupy 4 bytes without having to change the scope of the bitpacked modifier ? (hopefully leaving it defined as an enumeration and not have to resort to define it as a DWORD)
It seems to me that the incorrect size of the first structure is a bug but, since I am using an older version of the compiler and, I don't know if it happens in the current version, I haven't reported it.
Thank you for your help.