Using the sizeof operator with very large objects
As per K&R page 135 (and also this wikipedia page) the sizeof operator can be used to calculate the size of an object and returns the size in bytes as an unsigned integer of type size_t. Since the maximum unsigned integer value is 2 ^ 32, what would happen if I had to call sizeof on an object with a larger byte size than 2 ^ 32, for example say something 2 ^ 34 bytes in size. What would return the size? And is there a way to get around this size?
source to share
sizeof
returns size in bytes as an unsigned integer of typesize_t
size_t
It is an alias for one of the unsigned integer type ( unsigned int
, unsigned long long
, unsigned short
etc.). What specific unsigned integer type is implementation-defined.
size_t
guaranteed to be able to maintain the theoretical maximum object size on your system. So if yours size_t
is an unsigned 32 bit integer then it is not possible to create an object larger than 2 ^ 32 bytes on your system. Conversely, if you can create an object larger than 2 ^ 32 bytes, then it size_t
must be larger than a 32-bit unsigned integer large enough to be able to store the size of any object you might create.
source to share