When I want to use size_t
in C++, should I include <stddef.h>
or <cstddef>
? I have heard several people saying that <cstddef>
was a bad idea, and it should be deprecated. Why is that?
stddef.h
is the C header. The name size_t
is in global namespace in it. <cstddef>
, on the other hand, is a C++ header which wraps the C names into std namespace, which is naturally the C++ approach, so if you include <cstddef>
and the compiler is compliant you'll have to use std::size_t
. Clearly, in C++, C++ approach is more appropriate. HTH
Edit: Technically, the C header too may contain the names in the std namespace. But the C-headers (those that end with .h) introduce the names also to the global namespace (thus polluting it).