Maximum size of size_t
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.
Related videos on Youtube
Sunil Bojanapally
Updated on July 02, 2020Comments
-
Sunil Bojanapally almost 4 years
I know in
C
return type ofsizeof
operator issize_t
being unsigned integer type defined in<stdint.h>
. Which means max size of it should be65535
as stated inC99
standard 7.18.3:limit of size_t SIZE_MAX 65535
However in
gcc-4.8.2
header filestdint.h
has defined its size much greater than65535
contradicting to which is stated inC99
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.
-
phuclv almost 7 years
-
-
Sunil Bojanapally about 10 yearsNow it makes sense.
SIZE_MAX 65535
is minimum limit, which I got confused withlimit of size_t
thinking it as maximum limit. Thanks -
Keith Thompson about 10 years@SunEric: Right,
65535
is the minimum maximum. -
chux - Reinstate Monica about 10 yearsSuspect
SIZE_MAX
upper bound isUINTMAX_MAX
. -
Keith Thompson about 10 years@chux:
SIZE_MAX
can't be bigger thanUINTMAX_MAX
, but there's no specified upper bound onUINTMAX_MAX
. (It's only slightly less useful to say that the upper bound ofSIZE_MAX
isSIZE_MAX
.) -
chux - Reinstate Monica about 10 yearsVarious 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 likeSIZE_MAX
compared toLONG_MAX
. These 2 comes into interaction usingfseek()
(which returns long) to allocate a block to match a file usingmalloc()
which takes asize_t
.