Size "long long" in a 128-bit machine?

In a 128-bit RISC-V (or other 128-bit machine), how large are the "long" and "long" data types in C / C ++?

To clarify: what are the sizes that the compiler developer can expect when writing the limits.h file for such a machine, in the absence of other implementations for compliance?

+5
source share
3 answers

They can be of any size required by the compiler author, provided that they are at least the same as their predecessor ( long int for long long int and int for long int ) and satisfy the minimum ranges specified in the standards.

See, for example, 5.2.4.2 Numerical limits in C11 for the required minimum range:

 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 

Please note that this is not your complete set of two additions, since they must take into account the other two coding schemes, as well as additions and signed values, both of which have the concept of negative zero.

If you really want to know, you can simply view these 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; } 

My system is pretty standard swamp (and a bit 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 I have two additions on this system ( 8/7 mismatch on the last digit of negative / positive numbers), without 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, it should be able to tell you about such information.

+8
source

Include the limits.h header and print the size of the type you want.

  #include <limits.h> int main () { printf ("Size of long long is : %d\n", sizeof(long long)); return 0; } 
0
source

According to the standard, the named non-numeric integer signed character types:

 Type name Possible size signed char β€” 8 short β€” 16 int β€” 32 long β€” 64 long long β€” 128 intmax_t β€” 256 

("Without a number", I mean ignoring int_least8_t , int_fast16_t and int32_t , etc.)

These dimensions do not meet the requirements of standard C, but they are a standard progression with twice as many bits in each subsequent type. It would be reasonable to assume that on a 128-bit machine, long long will be 128 bits. If the author-compiler wanted to support 256-bit types, it would not be strange to make intmax_t into a 256-bit type. But besides that you have run out of names. Usually some of these types are the same size.

All standard requirements are a type of a type that was not longer in the list earlier than a type later in the list, that char is at least 8 bits, and short and int are at least 16 bits, that long is at least 32 bits, and long long - at least 64 bits.

-1
source

All Articles