Maximum size of size_t

75,798

The standard says that SIZE_MAX must be at least 65535.

It specifies no upper bound, and gcc's implementation is perfectly valid.

Quoting the reference you cited (emphasis added):

Its implementation-defined value shall be equal to or greater in magnitude (absolute value) than the corresponding value given below, with the same sign.

Share:
75,798

Related videos on Youtube

Sunil Bojanapally
Author by

Sunil Bojanapally

Updated on July 02, 2020

Comments

  • Sunil Bojanapally
    Sunil Bojanapally almost 4 years

    I know in C return type of sizeof operator is size_t being unsigned integer type defined in <stdint.h>. Which means max size of it should be 65535 as stated in C99 standard 7.18.3:

    limit of size_t
      SIZE_MAX             65535
    

    However in gcc-4.8.2 header file stdint.h has defined its size much greater than 65535 contradicting to which is stated in C99 standard as below shown,

    /* Limit of `size_t' type.  */
    # if __WORDSIZE == 64
    #  define SIZE_MAX              (18446744073709551615UL)
    # else
    #  define SIZE_MAX              (4294967295U)
    # endif
    

    Kindly help me in understanding why there is a difference or reason behind my misinterpretation.

  • Sunil Bojanapally
    Sunil Bojanapally about 10 years
    Now it makes sense. SIZE_MAX 65535 is minimum limit, which I got confused with limit of size_t thinking it as maximum limit. Thanks
  • Keith Thompson
    Keith Thompson about 10 years
    @SunEric: Right, 65535 is the minimum maximum.
  • chux - Reinstate Monica
    chux - Reinstate Monica about 10 years
    Suspect SIZE_MAX upper bound is UINTMAX_MAX.
  • Keith Thompson
    Keith Thompson about 10 years
    @chux: SIZE_MAX can't be bigger than UINTMAX_MAX, but there's no specified upper bound on UINTMAX_MAX. (It's only slightly less useful to say that the upper bound of SIZE_MAX is SIZE_MAX.)
  • chux - Reinstate Monica
    chux - Reinstate Monica about 10 years
    Various limits in C often have a relationship such as SIZE_MAX <= UINTMAX_MAX. (likely all unsigned are so limited - yet many do not know this - hence my comment.) But some limits are not well ordered like SIZE_MAX compared to LONG_MAX. These 2 comes into interaction using fseek() (which returns long) to allocate a block to match a file using malloc() which takes a size_t.