7.34 __offsetof_base keyword for related base classes in embedded assembler

The __offsetof_base keyword enables you to determine the offset from the beginning of an object to a base class sub-object within it.

__offsetof_base(D, B)

B must be an unambiguous, nonvirtual base class of D.

Returns the offset from the beginning of a D object to the start of the B base subobject within it. The result might be zero. The following example shows the offset (in bytes) that must be added to a D* p to implement the equivalent of static_cast<B*>(p).

__asm B* my_static_base_cast(D* /*p*/) // equivalent to:
                                       // return static_cast<B*>(p)
    if __offsetof_base(D, B) <> 0 // optimize zero offset case
        ADD r0, r0, #__offsetof_base(D, B)
    BX lr

The __offsetof_base, __mcall_*, and _vcall_offsetof_vfunc keywords are converted into integer or logical constants in the assembly source code. You can only use it in __asm functions, not in __cpp expressions.

Related concepts
7.26 Embedded assembler support in the compiler
7.29 Restrictions on embedded assembly language functions in C and C++ code
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.