[fpc-pascal] struct definition in C
Jonas Maebe
jonas.maebe at elis.ugent.be
Sun Mar 23 20:44:02 CET 2014
On 23/03/14 20:34, Darius Blaszyk wrote:
> Jonas Maebe schreef op 23 mrt '14:
>
>> It's not an initialization, it's a struct with bitfields. FPC currently
>> does not support C-compatible bitfield packing. To get a record with
>> equal alignment and size you can declare it as "record data: cuint;
>> end;", but there is currently no way in FPC to access the bitfields in a
>> portable way across platforms.
>>
> One more question. Why is it that there is no portable way to access the
> bitfields?
In part it's because no one has been able yet to come up with a natural
way to specify them in Pascal. Note that the C declaration both has a
base type (the "unsigned") and a bit width (the :x). Both pieces of
information are required to determine the layout of the struct and to
calculate its alignment. In part it's also because even with all that
information, it's quite complex and sometimes ABI-dependant to generate
a correct layout.
> Is that because of endian issues, or is there more to it?
> What about declaring the bitfields in a bitpacked record as "array of
> boolean"?
That will not result in the proper alignment of the struct, and
depending on how the struct is defined in C it may also not result in
mapping the bits to the correct locations. "bitpacked" only matches the
C behaviour if the struct has been declared with __attribute__((packed)).
Jonas
More information about the fpc-pascal
mailing list