Integer constant not in the representable range

Based on this (C11 6.4.4 / 2):

Limitations

2 Each constant must have a type, and the constant value must be in the range of represented values ​​for its type.

writes this correctly:

unsigned long long int a=18446744073709551615;

since an integer constant (which is a decimal constant ) cannot be unsigned. Therefore, the value is not in the range presented.

What happens with the exam? the value is not in the representable range of the decimal constant.

If I'm right, the integer constant can be expanded if there is no type in the list of correspondents that could represent the constant. The problem here is that decimal constants can only be expanded to signed integer constants. So the number 18446744073709551615has no type.

How can there be a conversion from not type to unsigned long long int?

+4
source share
2 answers

Based on two long comments that ultimately reached some sort of conclusion, I will subject this question to the answer:

They write it right:
unsigned long long int a=18446744073709551615;

Answer: Perhaps; it depends on the implementation.

a long long int LLONG_MAX, +9223372036854775807 (2 63 & minus; 1) (" 5.2.4.2 0,1). , , , , , long long, , , , . , ( 6.4.4.1), .

, long long int . , 6.2.5 4 ( " , " ), , int128_t, , a long long int. , , , 7 4, , " ". , , , , .

& sect; 4 , ( 5), . , .

, clang, gcc , , . :

warning: , , unsigned       [-Wimplicitly--]

, . C . , - , , . , , : , C (, , ), , . Java ++ Python "" , C, C, .

, clang gcc,

error: ,

. , .

+3

1.

2.

18446744073709551615 ​​ int, long int, long long int, 3 . 4 2.

, 5.

undefined, . , , .


( : ISO/IEC 9899: 201x)

1 (3. , 3.8 1)
 , , ,

2 (6.4.4 2)

3 (6.4.4.1 5)
, .

4 (6.4.4.1 6)
​​ , .

5 (5.1.1.3 1)
( ), , undefined .

+2

Source: https://habr.com/ru/post/1671658/


All Articles