__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. Example 24 shows the offset (in bytes) that must
be added to a D* p to implement the equivalent
of static_cast<B*>(p).
Example 24. 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)
endif
BX lr
}
The __offsetof_base, __mcall_*,
and _vcall_offsetof_vfunc keywords are converted into integer
or logical constants in the assembler source. You can only use it
in __asm functions, not in __cpp expressions.