Should I include stddef.h or cstddef for size_t

前端 未结 5 1666
暗喜
暗喜 2020-12-03 06:39

When I want to use size_t in C++, should I include or ? I have heard several people saying that

5条回答
  •  余生分开走
    2020-12-03 07:39

    Both are in the standard and, AFAIK, there to stay.

    The form cXXX always introduces the names in the std namespaces, the form XXX.h always introduces the names in the global namespace. Both may also put the names in the other namespace (at least in C++0X, it wasn't the case previously. As respecting that constraint make it impossible to build a C++ library from a C library you don't control, the constraint was removed. g++ suffers of that problem at least on the non glibc targets).

    For traditional Unix headers, in all implementation I've tested the form XXX.h includes the additional Unix identifier if you have the needed feature macros defined before. The behavior for the form cXXX was inconsistent between implementations. So in practice I use the XXX.h as I often need those declarations.

提交回复
热议问题