| |||
Home > Mixing C, C++, and Assembly Language > Calling between C, C++, and ARM assembly language > General rules for calling between languages |
The following general rules apply to calling between C, C++, and assembly language. For more details, see RealView Compilation Tools v3.0 Compiler and Libraries Guide.
The embedded assembler and compliance with the Application Binary Interface (ABI) for the ARM Architecture (base standard) [BSABI] make mixed language programming easier to implement. These assist you with:
name
mangling, using the __cpp
keyword
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 structures.
The following general rules apply to mixed language programming:
Use C calling conventions.
In C++, nonmember functions can be declared as extern
"C"
to specify that they have C linkage. In this release
of RealView® Compilation
Tools (RVCT), 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.
Functions that are declared extern "C"
cannot
be overloaded.
Assembly language modules must conform to the appropriate AAPCS 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 (nonmember)
C++ function, declare it extern "C"
to give it
C linkage.
Member functions (both static and non-static) always
have mangled names. Using the __cpp
keyword of
the embedded assembler means that you do not have to find the mangled
names manually.
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.
Nonstatic 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.
Static member functions do not receive an implicit this parameter.