User guide

they have no base classes or virtual functions. If such a struct has neither a user-defined copy assignment
operator or a user-defined destructor, it is a POD structure.
References are represented as pointers.
Pointers to data members and pointers to member functions occupy four bytes. They have the same null pointer
representation as normal pointers.
No distinction is made between pointers to C functions and pointers to C++ (non-member) functions.
Symbol name mangling
ARM C++ mangles external names of functions and static data members in a manner similar to that described in
section 7.2c of Ellis, M.A. and Stroustrup, B., The Annotated C++ Reference Manual (1990). The linker unmangles
symbols in messages.
C names must be declared as extern "C" in C++ programs. This is done already for the ARM ANSI C headers.
Refer to Using C header files from C++ for more information.
4.4.3 Examples
The following sections contain code examples that demonstrate:
Calling assembly language from C
Calling C from assembly language
Calling C from C++
Calling assembly language from C++
Calling C++ from C
Calling C++ from assembly language
Calling C++ from C or assembly language
Passing a reference between C and C++.
The examples assume the default non software-stack checking ATPCS variant because they perform stack
operations without checking for stack overflow.
Calling assembly language from C
Example 4-9 and Example 4-10 show a C program that uses a call to an assembly language subroutine to copy one
string over the top of another string.
Example 4-9 Calling assembly language from C
#include <stdio.h>
extern void strcopy(char *d, const char *s);
int main()
{ const char *srcstr = "First string - source ";
char dststr[] = "Second string - destination ";
/* dststr is an array since we're going to change it */
printf("Before copying:\n");
printf(" %s\n %s\n",srcstr,dststr);
strcopy(dststr,srcstr);
printf("After copying:\n");
printf(" %s\n %s\n",srcstr,dststr);
return (0);
}
Example 4-10 Assembly language string copy subroutine
AREA SCopy, CODE, READONLY
EXPORT strcopy
strcopy ; r0 points to destination string.
; r1 points to source string.
LDRB r2, [r1],#1 ; Load byte and update address.
STRB r2, [r0],#1 ; Store byte and update address.
CMP r2, #0 ; Check for zero terminator.
BNE strcopy ; Keep going if not.
MOV pc,lr ; Return.
END
Example 4-9 is located in install_directory\examples\asm as strtest.c and scopy.s. Follow these steps
to build the example from the command line:
1. Type armasm -g scopy.s to build the assembly language source.
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-12