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.
On a typical 64-bit system, the size_t will be 64-bit, but unsigned int will be 32 bit. So we cannot use them interchangeably. One standard recommendation is that the size_t be at most as big as an unsigned long.
No; size_t is not necessarily whatever you mean by 'the word size' of the machine that will run the code (in the case of cross-compilation) or that compiled the code (in the normal case where the code will run on the same type of machine that compiled the code).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With