Convert int & # 8594; unsigned long long defined by standard

I cannot find an exact specification of how the value is intconverted to unsigned long longin the standard. Various similar transformations will be defined, such as int โ†’ unsigned, unsigned โ†’ int (UB if negative), unsigned long long โ†’ int, etc.

For example, GCC is -1converted to 0xffffffffffffffff, not to 0x00000000ffffffff. Can I rely on this behavior?

+4
source share
3 answers

, , max unsigned long long + 1 -1, max unsigned long long. ++ 4.7 , :

, ( 2 , ). [. ( ). -end note]

, C99, C99 , 6.3.1.3 Signed :

, , , . 49)

49 :

, .

+2

, :

++ 11 ยง 4.7 [conv.integral]/2 :

, ( 2 , ).

, -1 ( 2 sizeof(unsigned long long)), unsigned long long.

+1

. , int v unsigned long u , u= K * 2 n + v, K - 0, 1, n - unsigned long. , v , 2 n.


2 ++ , . n 2 n. ( std::numeric_limits ).


, , , , -, undefined, unsigned . , , Visual ++ . , , , ( ) .

+1

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


All Articles