is size_t a keyword?or a macro?

Discussion in 'C++' started by Guo Congbin, Jun 17, 2004.

  1. Guo Congbin

    Guo Congbin Guest

    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
     
    Guo Congbin, Jun 17, 2004
    #1
    1. Advertising

  2. Guo Congbin wrote:

    > 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
    <cstddef>, size_t is in the std namespace (std::size_t).

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

    --
    Russell Hanneken

    Use ROT13 to decode my email address.
     
    Russell Hanneken, Jun 17, 2004
    #2
    1. Advertising

  3. Guo Congbin

    Default User Guest

    Guo Congbin wrote:
    >
    > 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.


    It's usually a typedef. If it isn't directly defined in <cstddef> then
    it's probably in a header included by it.

    > 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
     
    Default User, Jun 17, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guo Congbin
    Replies:
    4
    Views:
    3,910
    Ioannis Vranos
    Jun 17, 2004
  2. Replies:
    6
    Views:
    459
    Peter Otten
    May 10, 2007
  3. Hamilton, William

    RE: keyword checker - keyword.kwlist

    Hamilton, William, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    359
  4. Alex Vinokur
    Replies:
    9
    Views:
    801
    James Kanze
    Oct 13, 2008
  5. Alex Vinokur
    Replies:
    1
    Views:
    583
Loading...

Share This Page