Objc.checkOffsetof

Issues a compile time error if the .offsetof/.tupleof property is used on a field of an Objective-C class.

To solve the fragile base class problem in Objective-C, fields have a dynamic offset instead of a static offset. The compiler outputs a statically known offset which later the dynamic loader can update, if necessary, when the application is loaded. Due to this behavior it doesn't make sense to be able to get the offset of a field at compile time, because this offset might not actually be the same at runtime.

To get the offset of a field that is correct at runtime, functionality from the Objective-C runtime can be used instead.

  1. void checkOffsetof(Expression expression, AggregateDeclaration aggregateDeclaration)
    class Objc
  2. void checkTupleof(Expression expression, TypeClass type)

Parameters

expression

the .offsetof/.tupleof expression

aggregateDeclaration

the aggregate declaration the field of the .offsetof/.tupleof expression belongs to

See Also

Meta