User guide

4.4 Calling between C, C++, and ARM assembly language
This section provides examples that can help you to call C and assembly language code from C++, and to call C++
code from C and assembly language. It also describes calling conventions and data types.
You can mix calls between C and C++ and assembly language routines provided you follow the appropriate
procedure ATPCS call standard. For more information on the ATPCS, see Chapter 2 Using the Procedure Call
Standard.
Note
The information in this section is implementation dependent and might change in future toolkit releases.
4.4.1 General rules for calling between languages
The following general rules apply to calling between C, C++, and assembly language.
You should not rely on the following C++ implementation details. These implementation details are subject to change
in future releases of ARM C++:
the way names are mangled
the way the implicit this parameter is passed
the way virtual functions are called
the representation of references
the layout of C++ class types that have base classes or virtual member functions
the passing of class objects that are not plain old data (POD) structures.
The following general rules apply to mixed language programming:
Use C calling conventions.
In C++, non-member functions can be declared as extern "C" to specify that they have C linkage. In this
release of ADS, having C linkage means that the symbol defining the function is not mangled. C linkage can be
used to implement a function in one language and call it from another.
Note
Functions that are declared extern "C" cannot be overloaded.
Assembly language modules must conform to the appropriate ARM/Thumb Procedure Calls Standard for the
memory model used by the application.
The following rules apply to calling C++ functions from C and assembly language:
To call a global (non-member) C++ function, declare it extern "C" to give it C linkage.
Member functions (both static and non-static) always have mangled names.
C++ inline functions cannot be called from C unless you ensure that the C++ compiler generates an out-of-line
copy of the function. For example, taking the address of the function results in an out-of-line copy.
Non-static member functions receive the implicit this parameter as a first argument in r0, or as a second
argument in r1 if the function returns a non int-like structure. This might change in future implementations. Static
member functions do not receive an implicit this parameter.
4.4.2 Information specific to C++
The following applies specifically to C++.
C++ calling conventions
ARM C++ uses the same calling conventions as ARM C with the following exceptions:
When an object of type struct or class is passed to a function and the object has an explicit copy
constructor, the object will be copied by the calling code or by the subroutine (callee). If the constructor is
overloaded the caller makes the copy. If the constructor is not overloaded, the callee makes the copy.
Non-static member functions are called with the implicit this parameter as the first argument, or as the second
argument if the called function returns a non int-like struct. This might change in future implementations.
C++ data types
ARM C++ uses the same data types as ARM C with the following exceptions and additions:
C++ objects of type struct or class have the same layout as would be expected from the ARM C compiler if
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-11