Skip to contentSkip to conversation

double exclamation (!!) suckage in the kernel

DISCUSSION Bodo Eggert 2 participants 3 messages May 26, 2007 – May 29, 2007 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines · David Miller

"!!" is used in contexts where pointers might be being tested as well as plain integers, the "!!" turns a pointer into the equivalent integer boolean for testing.

Quoted 7 lines
Quoted 2 lines

NULL pointers become 0
non-NULL pointers become 1

Though,
if(!!ptr)
is effectively the same as
if(ptr)

Not exactly, if(foo) is the same as if( (int) foo), which is not guaranteed to result in non-null values for non-null pointers. ISO 9899/1999 says: "Any pointer may be converted to an integer type. [...]
The result need not be in the range of values of any integer type."

"if(!!foo)" is the same as "if(0 == (0 == foo))", which is (I asume) the same as "if(0 == ((type_of_foo)NULL == foo))", or if((type_of_foo)NULL != foo).

Signature · 4 lines
Funny quotes:
11. Atheism is a non-prophet orgainization.

Friß, Spammer: [email protected] [email protected]
#4 lore raw
Quoted 2 lines · Bodo Eggert

Not exactly, if(foo) is the same as if( (int) foo), which is not guaranteed to result in non-null values for non-null pointers.

RTFStandard.

Quoted 2 lines

ISO 9899/1999 says: "Any pointer may be converted to an integer type. [...]
The result need not be in the range of values of any integer type."

... and it sure as hell does *NOT* say that controlling expression of if statement is converted to an integer type. For pointers of for anything else. if (v) is the same as if (v != 0) [6.8.4.1p2], and if v is a pointer, 0 in that comparison becomes a null pointer constant [6.5.9p5].

#5 lore raw
Quoted 5 lines · Al Viro
Quoted 2 lines · Bodo Eggert

Not exactly, if(foo) is the same as if( (int) foo), which is not guaranteed to result in non-null values for non-null pointers.

RTFStandard.

... and don´t forget half of it untill you look up the next thing. Yes, obviously I misremembered "compares equal to" as "is".