[fpc-pascal] Class var in record breaks pointer cast
Martin Frb
lazarus at mfriebe.de
Thu Feb 5 15:45:07 CET 2026
On 05/02/2026 14:42, Martin Frb via fpc-pascal wrote:
> On 05/02/2026 14:34, Hairy Pixels via fpc-pascal wrote:
>> Is this a bug? Adding the class var field changes prints 0 and
>> without it prints 100 as expected. The class var is just a static
>> field that isn't actually part of the record so how could it affect
>> the memory layout?
>
> A class var is (as the name suggest "not instance") not part of the
> instance. (instead a scoped global var).
>
> So a pointer to the instance can not be to the memory that holds the
> class var data.
Sorry, strike above / messed up the field names while reading. You
aren't accessing "z".
My bad.
>
>>
>> type
>> TMyRec = record
>> class var z: UInt32;
>> x, y: UInt32;
>> end;
>>
>> var
>> r: TMyRec;
>> p: pointer;
>> begin
>> r.x := 100;
>> p := @r;
>>
>> writeln(PUInt32(p)^);
>> end.
>>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list