[fpc-pascal] Implementation of variant records
Sven Barth
pascaldragon at googlemail.com
Sun Jul 7 12:54:01 CEST 2019
Am 07.07.2019 um 02:55 schrieb Ralf Quint:
> On 7/6/2019 12:21 PM, Florian Klaempfl wrote:
>> Am 05.07.2019 um 13:53 schrieb Ralf Quint:
>>> Shouldn't a PACKED Record guarantee that values are aligned at the byte
>>> level?
>> It does in TP, but the ISO says only that it shall be economised.
>>
> Well, the ISO is probably what has done most of the damage to Pascal.
> AFAIK, the ISO doesn't not actually specify any "packed record" per
> se, but there is an explicit PACK and UNPACK procedures to more
> economically store sets and arrays (and possibly records, I would have
> to look up the ISO text to be certain). For example this would be
> something to create bit fields, pretty much the only feature of C that
> I sometimes miss in (Free)Pascal.
You mean like this?
=== code begin ===
struct Test
{
uint8_t field1;
uint16_t bfield1 : 1;
uint16_t bfield2 : 1;
uint16_t bfield3 : 3;
uint16_t bfield4 : 5;
uint16_t bfield5 : 1;
uint16_t field2;
};
=== code end ===
=== code begin ===
type
TTest = bitpacked record
field1: UInt8;
bfield1: 0..1;
bfield2: 0..1;
bfield3: 0..7;
bfield4: 0..31;
bfield5: 0..1;
pad: UInt8; // needed due to bitpacked
field2: UInt16;
end;
=== code end ===
The size of both records is 6. :)
Regards,
Sven
More information about the fpc-pascal
mailing list