In a 128-bit RISC-V (or other 128-bit machine), how big are "long" and "long long" data types in C/C++?
To clarify: what are the sizes that an implementer of a compiler might be expected to use when writing the limits.h file for such a machine, in the absence of other implementations to conform to?
They can be any size the compiler writer wanted, subject to them being at least as large as their predecessor type (long int
for long long int
and int
for long int
) and satisfying the minimum ranges set out in the standards.
See, for example, 5.2.4.2 Numerical limits
in C11, which states the minimum range required:
long int
LONG_MIN -2147483647 // −(2^31 − 1)
LONG_MAX +2147483647 // 2^31 − 1
long long int
LLONG_MIN -9223372036854775807 // −(2^63 − 1)
LLONG_MAX +9223372036854775807 // 2^63 − 1
Note that these aren't your full two's complement range since they have to account for the other two encoding schemes as well, ones' complement and sign-magnitude, both of which have the concept of negative zero.
If you really want to know, you can just look up those values in the limits.h
header file, or compile and run:
#include <stdio.h>
#include <limits.h>
int main (void) {
printf ("BITS/CHAR %d\n", CHAR_BIT);
printf ("CHARS/SHORT %d\n", sizeof(short));
printf ("CHARS/INT %d\n", sizeof(int));
printf ("CHARS/LONG %d\n", sizeof(long));
printf ("CHARS/LLONG %d\n", sizeof(long long));
putchar ('\n');
printf ("SHORT MIN %d\n", SHRT_MIN);
printf ("SHORT MAX %d\n", SHRT_MAX);
printf ("INT MIN %d\n", INT_MIN);
printf ("INT MAX %d\n", INT_MAX);
printf ("LONG MIN %ld\n", LONG_MIN);
printf ("LONG MAX %ld\n", LONG_MAX);
printf ("LLONG MIN %lld\n", LLONG_MIN);
printf ("LLONG MAX %lld\n", LLONG_MAX);
return 0;
}
On my system, a fairly bog-standard one (and slightly reformatted to look pretty):
BITS/CHAR 8
CHARS/SHORT 2
CHARS/INT 4
CHARS/LONG 4
CHARS/LLONG 8
SHORT MIN -32768
SHORT MAX 32767
INT MIN -2147483648
INT MAX 2147483647
LONG MIN -2147483648
LONG MAX 2147483647
LLONG MIN -9223372036854775808
LLONG MAX 9223372036854775807
So it looks like, on this system, I have two's complement (the 8/7
mismatch on the last digit of negative/positive numbers), no padding bits, 16-bit short int
, 32-bit int
and long int
and 64-bit long long int
.
If you run similar code in your own environment, that should be able to tell you similar information for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With