Why is the sizeof(int) == sizeof(long)?

A long, as far as I know, is 8 bytes. Is this correct?

No, this is not correct. The C and C++ specifications only state that long must be greater than or equal to 32 bits. int can be smaller, but on many platforms, in C and C++, long and int are both 32 bits.

This is a very good reason to prefer fixed width integer types such as int64_t if they’re available to you and you’re using C99 or a framework which provides you an equivalent type.

Leave a Comment