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

2 answers


returns size in bytes as an unsigned integer of typesize_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.


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.



I think you are reading this wrong.

"Unsigned integer" does not mean "type unsigned int

". It can also, for example, be unsigned long long

, which can be (much) larger. Also, there is of course no requirement or specification that says it is unsigned int

limited to 32 bits.



All Articles