The recommended way to include the C standard library header <foo.h>
in C++ is to include the corresponding C++ header <cfoo>
.
Based on my experience this puts some of of the corresponding C constructs into the std
namespace, but others at global scope, and sometimes they appear in both places (i.e., in the std
namespace and at global scope).
It depends on both the compiler (some like to include size_t
only in std
and not at global scope, others always have it at global scope), and on the construct (for example neither assert
nor error
ever seem to appear in the std
namespace despite including cassert
and cerrno
).
What is required of the standard, and is there any simple rule to portably accessing C constructs in relation to the location in or out of the std
namespace (something better than using namespace std
)?
This question covers the same ground, but the answers there already reflect my understanding that cfoo
puts everything in std
- but doesn't answer the question of why things like assert
and errno
don't appear in std
in that case, and how to know the full list of similar "exceptions".