is size_t a keyword?or a macro?

G

Guo Congbin

if size_t is a macro, where is the defination? i look it up in the stddef.h,
but i find nothing about size_t.

this is the content of stddef.h of my system,
#ifndef _LINUX_STDDEF_H
#define _LINUX_STDDEF_H

#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif

#undef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#endif

i regard the size_t as unsigned int or unsigned long, and i am not very
confidence.

Please help me!

yours Guocongbin
2004.6.17
 
R

Russell Hanneken

Guo said:
if size_t is a macro, where is the defination?

size_t is a typedef, not a keyword or a macro. The C standard says it's
declared in several header files, including <stddef.h>. In C++, the
<stddef.h> header is deprecated, and you should use <cstddef> instead. In
i look it up in the stddef.h, but i find nothing about size_t.

this is the content of stddef.h of my system,
[snip]

The header file you quoted doesn't seem to conform to the requirements of
the C standard. Perhaps there's another stddef.h file somewhere? If not,
try looking in cstddef, stdio.h, stdlib.h, string.h, time.h, or wchar.h.
i regard the size_t as unsigned int or unsigned long, and i am not very
confidence.

The C++ standard defers to the C standard on this issue. The C standard
says only that size_t is the type returned by the sizeof operator, and that
it is some sort of unsigned integral type. The specific type varies from
implementation to implementation. It might even be a platform-specific type
(I think the Microsoft <stddef.h> typedefs it to some type called unsigned
__int64). If you really need to know what size_t is, you'll have to find it
in your header files, or possibly in the documentation that comes with your
library.
 
D

Default User

Guo said:
if size_t is a macro, where is the defination? i look it up in the stddef.h,
but i find nothing about size_t.

i regard the size_t as unsigned int or unsigned long, and i am not very
confidence.

Why do you care? The standard says that size_t is an unsigned integral
type large enough to hold the size of the largest required object in the
implementation (SIZE_MAX). That's all you need to know.



Brian Rodenborn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top