User guide

4.3 Using C header files from C++
This section describes how to use C header files from your C++ code. C header files must be wrapped in extern
"C" directives before they are called from C++.
4.3.1 Including system C header files
To include standard system C header files, such as stdio.h, you do not have to do anything special. The standard
C header files already contain the appropriate extern "C" directives. For example:
// C++ code
#include <stdio.h>
int main()
{
//...
return 0;
}
The C++ standard specifies that the functionality of the C header files is available through C++ specific header files.
These files are installed in install_directory\include, together with the standard C header files, and can be
referenced in the usual way. For example:
// C++ code
#include <cstdio>
int main()
{
// ...
return 0;
}
In ARM C++, these headers simply #include the C headers.
Note
The C standard header files and their C++ veneer headers are available in the compiler's in-memory file system.
Refer to C compilers in the Compiler and Libraries Guide
for more information.
4.3.2 Including your own C header files
To include your own C header files, you must wrap the #include directive in an extern "C" statement. You can
do this in two ways:
When the file is #included. This is shown in Example 4-7.
By adding the extern "C" statement to the header file. This is shown in Example 4-8.
Example 4-7 Directive before include file
// C++ code
extern "C"{
#include "my-header1.h"
#include "my-header2.h"
}
int main()
{
// ...
return 0;
}
Example 4-8 Directive in file header
/* C header file */
#ifdef __cplusplus /* Insert start of extern C construct */
extern "C" {
#endif
/* Body of header file */
#ifdef __cplusplus /* Insert end of extern C construct */
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-9