6.43 Calling a virtual member function

The following example shows code that calls a virtual function in either a virtual or nonvirtual base.

// rp contains a D* and we want to do the equivalent of rp->f() where f is a
// virtual function
// all arguments other than the this pointer are already set up
// assumes f does not return a struct
 if __mcall_is_in_vbase(D, f)
    LDR r12, [rp]                                 // fetch vtable pointer
    LDR r0, [r12, #-__mcall_offsetof_vbase(D, f)] // fetch the base offset
    ADD r0, r0, rp                                // do this adjustment
    LDR r12, [r0]                                 // fetch vbase vtable pointer
    MOV r0, rp                                    // set up this pointer for D*
    LDR r12, [rp]                                 // fetch vtable pointer
    ADD r0, r0, #__mcall_this_offset(D, f)        // do this adjustment
    MOV lr, pc                                    // prepare lr
    LDR pc, [r12, #__vcall_offsetof_vfunc(D, f)]  // calls rp->f()
Related concepts
6.26 Embedded assembler support in the compiler
6.41 Calling nonstatic member functions in embedded assembler
6.42 Calling a nonvirtual member function
Non-ConfidentialPDF file icon PDF versionARM DUI0375F
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.