c++c-preprocessorc++98

stdint for C++98 (gcc/clang)


Why do GCC/clang complain about including cstdint but not about stdint.h when compiling for C++98?

Compiling with -std=c++98 -x c++ -Wall -Wextra -pedantic outputs for #include <cstdint>:

This file requires compiler and library support for the ISO C++ 2011 standard.

According to the C++98 standard none of the headers are defined.


Solution

  • GCC

    The #include directive is executed by the GNU C preprocessor (CPP) for C and C++ sources. The standard system directories for header files, searched at by default by CPP, contain the headers for the C Standard Library. For C++ additional directories are used for the search first. Thus even for C++ source the C Standard Library headers are available by default. The header stdint.h found is thus not the compatibility header available since C++11. But instead the C Standard Library header available since C99.

    I deduced this from an old version of the GNU CPP documentation:

    GCC looks in several different places for headers. [...] For C++ programs, it will also look in [...], first.

    See also the GNU CPP options -nostdinc and -nostdinc++.

    ⚠ I assume this behavior is not backed by the C++ Standard.