Is size_t开发者_如何学C only in C++ standard or C standard as well?
I cannot find a C header in the "/usr/include" tree that defines size_t.
If it is not in the C std, is GCC just doing some magic to make things work?
Thanks, Chenz
size_t
is defined in both <stddef.h>
and <stdlib.h>
From C99 draft:
7.17 Common definitions <stddef.h>
The following types and macros are defined in the standard header
<stddef.h>
. Some are also defined in other headers, as noted in their respective subclauses.The types are [-snip-]
size_t
which is the unsigned integer type of the result of the
sizeof
operator; [-snip-]
size_t is from the C standard library
It is declared in
#include <stddef.h> //For C
#include <cstddef> //For C++
$ grep -R -P "typedef.*\s+size_t;" /usr/include/ 2> /dev/null
will give you a list of files that define size_t
size_t is in stdlib.h for C (or cstdlib.h in C++).
It is defined in string.h in ansi c.
精彩评论