Recent

Author Topic: equivalent to C/C++ "offsetof" ?  (Read 249 times)

jamie

  • Hero Member
  • *****
  • Posts: 7827
equivalent to C/C++ "offsetof" ?
« on: July 11, 2026, 02:32:18 am »
I used to be able to do something like this:

     UintPtr(@TSomeRecord(Nil).AmemberField);

I could of use "Integer" as the cast instead, can't remember but, it will give me the offset value of the field.

Jamie
The only true wisdom is knowing you know nothing

Fibonacci

  • Hero Member
  • *****
  • Posts: 1024
  • Behold, I bring salvation - FPC Unleashed
Re: equivalent to C/C++ "offsetof" ?
« Reply #1 on: July 11, 2026, 02:44:35 am »
Code: Pascal  [Select][+][-]
  1. writeln(UintPtr(@TSomeRecord(Nil^).AmemberField)); // objfpc
  2. writeln(OffsetOf(TSomeRecord.AmemberField));       // unleashed  
FPC Unleashed: async/await, parallel for, match, tuples, string interpolation, inline vars, autofree, no-RTTI & tons more. Star on GitHub

jamie

  • Hero Member
  • *****
  • Posts: 7827
Re: equivalent to C/C++ "offsetof" ?
« Reply #2 on: July 11, 2026, 12:58:11 pm »
Looks interesting. The unleased FPC compiler, that is.
The only true wisdom is knowing you know nothing

creaothceann

  • Sr. Member
  • ****
  • Posts: 389
Re: equivalent to C/C++ "offsetof" ?
« Reply #3 on: Today at 12:50:49 am »
*unleashed

 

TinyPortal © 2005-2018