In the C99 standard they introduced long long
. What is the purpose of this? In my (limited) C programming experience, I've only every seen a 4-byte int and an 8-byte long. For example, from Compiler Explorer:
If long
is already 8
then, why is it necessary to add another long long
type? What does this do to the compiler/architecture?
If long is already 8 then, why is it necessary to add another long long type? What does this do to the compiler/architecture?
"If long is already 8" is not always true as much code exists that relies on 32-bit long
and int
as 32 or 16 bits.
Requiring long
as 64-bit would break code bases. This is a major concern.
Yet requiring long
to remain 32-bit (and no long long
) would not make for access to standard 64-bit integers, hence a rationale for long long
.
Allowing long
as either 32-bit or 64-bit (or others) allows for transition.
Various functions pass in/return long
like fseek(), ftell()
. They benefit from long
being more than 32-bit for large file support.
Recommended practice encourages a wider long
: "The types used for size_t
and ptrdiff_t
should not have an integer conversion rank greater than
that of signed long int
unless the implementation supports objects large enough to make this necessary." This relates to memory sizes exceeding 32-bit.
Perhaps in the future an implementation may use int/long/long long/intmax_t
as 32/64/128/256 bits.
IAC, I see fixed width types intN_t
increasing in popularity over long
and long long
. I tend to use fixed width types or bool
, (unsigned
) char
, int
/unsigned
, size_t
, (u
)intmax_t
and leave signed char
, (unsigned
) short
, (unsigned
) long
, (unsigned
) long long
for special cases.