3.3 Including system C header files from C++

When including C header files in C++, the #include syntax used determines what namespace to use and therefore the type of access you have.

C header files must be wrapped in extern "C" directives before they are included from C++. Standard system C header files already contain the appropriate extern "C" directives so you do not have to take any special steps to include such files.

For example:

#include <stdio.h>
int main()
{
    ...       // C++ code
    return 0;
}

If you include headers using this syntax, all library names are placed in the global namespace.

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:

#include <cstdio>

In ARM C++, these headers #include the C headers. If you include headers using this syntax, all C++ standard library names are defined in the namespace std, including the C library names. This means that you must qualify all the library names by using one of the following methods:

  • specify the standard namespace, for example:

    std::printf("example\n");
    
  • use the C++ keyword using to import a name to the global namespace:

    using namespace std;
    printf("example\n");
    
  • use the compiler option --using_std.

Non-ConfidentialPDF file icon PDF versionARM DUI0471M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.