is size_t a keyword?or a macro?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guo Congbin

    is size_t a keyword?or a macro?

    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(__cplus plus)
    #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


  • Russell Hanneken

    #2
    Re: is size_t a keyword?or a macro?

    Guo Congbin wrote:
    [color=blue]
    > if size_t is a macro, where is the defination?[/color]

    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).
    [color=blue]
    > 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,[/color]
    [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.
    [color=blue]
    > i regard the size_t as unsigned int or unsigned long, and i am not very
    > confidence.[/color]

    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
    eunaarxra@cbobk .pbz
    Use ROT13 to decode my email address.


    Comment

    • Default User

      #3
      Re: is size_t a keyword?or a macro?

      Guo Congbin wrote:[color=blue]
      >
      > 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.[/color]

      It's usually a typedef. If it isn't directly defined in <cstddef> then
      it's probably in a header included by it.
      [color=blue]
      > i regard the size_t as unsigned int or unsigned long, and i am not very
      > confidence.[/color]

      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

      Comment

      Working...