Is (uint64_t)-1 guaranteed to yield 0xffffffffffffffff?

cmaster - reinstate monica

I know, that it is well defined by the C standard that (unsigned)-1 must yield 2^n-1, i. e. an unsigned integer with all its bits set. The same goes for (uint64_t)-1ll. However, I cannot find something in the C11 standard that specifies how (uint64_t)-1 is interpreted.

So, the question is: Is there any guarantee in the C standard, which of the following holds true?

(uint64_t)-1 == (uint64_t)(unsigned)-1   //0x00000000ffffffff
(uint64_t)-1 == (uint64_t)(int64_t)-1    //0xffffffffffffffff
R.. GitHub STOP HELPING ICE

Yes. See C11 6.3.1.3 Signed and unsigned integers:

1 When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.

2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.60)

3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.

60) The rules describe arithmetic on the mathematical value, not the value of a given type of expression.

Case 2 applies, so -1 is reduced modulo 0x10000000000000000 to yield 0xffffffffffffffff.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why is 0x7FFFFFFFull | (1 << 31) returning 0xFFFFFFFFFFFFFFFF in C++?

From Dev

!0 guaranteed to be 1 in C89?

From Dev

Access violation reading location 0xFFFFFFFFFFFFFFFF

From Dev

Bit manipulation: compute sum over all bits (aka number of 1's) in a uint64_t

From Dev

Is bool guaranteed to be 1 byte?

From Dev

Is EOF guaranteed to be -1?

From Dev

0xFFFFFFFFFFFFFFFF Traceback with Skype4Py

From Dev

0xFFFFFFFFFFFFFFFF Traceback with Skype4Py

From Dev

ES6 yield (yield 1)(yield 2)(yield 3)()

From Dev

Division by integers guaranteed to yield same floating point number?

From Dev

Why (int)(14/13 - 0.001) yield 0 and not 1?

From Dev

Why (int)(14/13 - 0.001) yield 0 and not 1?

From Dev

Why is (int64_t)-1 + (uint32_t)0 signed?

From Dev

Is the truncated to 64 bit sha1 of a 64 bit number guaranteed to be unique?

From Dev

Is 0 divided by infinity guaranteed to be 0?

From Dev

Is "for x in range(3): print x" guaranteed to print "0, 1, 2" in that order?

From Dev

Is it guaranteed by C++ standard that std::basic_string::npos + 1 == 0?

From Dev

Is BigInteger.longValue() guaranteed to preseve the unsigned binary for 2^63 <= x <= 2^64-1?

From Dev

Is the alignment of char in C (and C++) guaranteed to be 1?

From Dev

Arduino: Converting uint64_t to string

From Dev

Converting unsigned char* to uint64_t

From Dev

Wrong calculation result on uint64_t

From Dev

check if uint64_t is defined

From Dev

Cast chrono::milliseconds to uint64_t?

From Dev

Returned uint64_t seems truncated

From Dev

Comparing uint64_t with an unsigned char*

From Dev

Returned uint64_t seems truncated

From Dev

Convert uint64_t to cv::mat

From Dev

Convert uint64_t to uint8_t[8]

Related Related

HotTag

Archive