W3cubDocs

/Crystal

offsetof

An offsetof expression returns the byte offset of an instance variable in a struct or class type. It accepts the type as first argument and the instance variable name prefixed by an @ as second argument:

offsetof(Type, @ivar)

This is a low-level primitive and only useful if a C API needs to directly interface with the data layout of a Crystal type.

Example:

struct Foo
  @x = 0_i64
  @y = 34_i32
end

offsetof(Foo, @y) # => 8

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/offsetof.html