I’m a novice C programmer; this might be a naive question to ask but please bear with me. I learnt that the storage size of char
, short
, int
, long
, long long
, float
, double
, and long double
are implementation dependent and can vary greatly. When I used sizeof(long)
on my machine, it returned me 8 bytes
, but when used the same function upon long long
it returned 8 bytes
as well. Therefore I thought, since my CPU is based on X64 ISA, it might only support 64 bits / 8 bytes at max. But when I used the same function for long double
the result was 16 bytes
.
How come long double
can be 16 bytes wide but not long long
? If long long
is same as long
what’s the point of having it? And one more question, how does my CPU truly handle long double
with 128 bits wide when the registers’ size of my CPU is 64 bits?
Additional Information: I use gcc (GCC) 12.2.0
, if it has something to do with the compiler.
#include <stdio.h>
int main(void) {
printf("%dn", sizeof(long));
printf("%dn", sizeof(long long));
printf("%dn", sizeof(long double));
return 0;
}
The result was as follow:
8
8
16