tags:

views:

172

answers:

5

Is size_t 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

+4  A: 

size_t is defined in both <stddef.h> and <stdlib.h>

James McNellis
A: 

size_t is in stdlib.h for C (or cstdlib.h in C++).

Brendan Long
A: 

It is defined in string.h in ansi c.

Nick
+2  A: 

size_t is from the C standard library

It is declared in

#include <stddef.h>  //For C
#include <cstddef>   //For C++
Ramon Zarazua
+2  A: 

From C99 draft:

7.17 Common definitions <stddef.h>

  1. 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.

  2. The types are [-snip-]

    size_t
    

    which is the unsigned integer type of the result of the sizeof operator; [-snip-]

KennyTM
The "other headers" part applies to `size_t`, it's also declared in `<stdlib.h>` (see 7.20/2).
sth