wewmi
wewmi

Reputation: 45

Unsigned long long with negative value

while exploring linux code, came across many definition like below. If ULL is unsigned long long, why it has negative value -11? What the value of below macro?

#define BTRFS_FREE_SPACE_OBJECTID -11ULL

Upvotes: 0

Views: 866

Answers (2)

milevyo
milevyo

Reputation: 2180

 unsigned int a=-1;

is the same as:

 unsigned int a=0xffffffff;

Upvotes: 1

gnasher729
gnasher729

Reputation: 52538

-11ULL is the same as - (11ULL). 11ULL is an unsigned long long with value 11. If you read up how arithmetic operations on unsigned types work, if the mathematical result does not fit into the range, then the largest value + 1 is added or subtracted repeatedly.

The mathematical result -11 doesn't fit, so the largest unsigned long long + 1 is added, and -11ULL gives ten less than the largest possible unsigned long long value. A huge positive number, not negative.

Upvotes: 3

Related Questions