Re: [fpc-pascal] Class var in record breaks pointer cast
Martin Frb via fpc-pascal schrieb am Do., 5. Feb. 2026, 15:54: > On 05/02/2026 15:45, Martin Frb via fpc-pascal wrote: > "class var" seems to start a section, like "public type" > It not only seems so, it *is* so. While it's not explicitly me mentioned for records it is somewhat mentioned for classes: https://www.freepascal.org/docs-html/current/ref/refsu24.html#x74-980006.3.2 Regards, Sven > ___ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Class var in record breaks pointer cast
On Feb 5, 2026 at 9:54:04 PM, Martin Frb via fpc-pascal < [email protected]> wrote: > type > TMyRec = record > class var >z: UInt32; > var // new section, normal fields // tested 3.3.1 > x, y: UInt32; > end; > oh it was a parsing issue, good find, thanks. For some reason I thought "class" could only contain one list of names. ___ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Class var in record breaks pointer cast
On 05/02/2026 15:45, Martin Frb via fpc-pascal wrote: type TMyRec = record class var z: UInt32; x, y: UInt32; end; Ok found something... I tried debugging, and noted that with the class var, the record had no debug info for any field. And expecting memory did not reveal any data, if wrote to other fields. "class var" seems to start a section, like "public type" So all 3 fields in your example are class vars. Try the below: type TMyRec = record class var z: UInt32; var // new section, normal fields // tested 3.3.1 x, y: UInt32; end; ___ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Class var in record breaks pointer cast
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 - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Class var in record breaks pointer cast
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. 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 - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
