For reference: The offsetof
macro(!) takes a struct
data type and a member of the specified struct as arguments and returns an integer offset of the given member relative to the beginning of the struct. See the detailed overview and references.
The logic behind the generic offsetof
is quite simple and can be reproduced in Delphi with ease (more or less) (literally with ease, elimination of predeclared pointer type requirement makes it a basic inline expression, see David Heffernan's answer and comment about swapping reference and dereference operators) as in-place code. However, I see absolutely no way to convert the in-place code solution to the reusable function. Can we actually do that?