[lkml]   [2005]   [Aug]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: [PATCH] spi
> > It was explained to me that the !pointer test wasn't guaranteed to be
> > equivalent because of the way that the test is handled.
> Whoever explained that to you was wrong. is the final word on
> how "!x" is interpreted, and it *says* in the *text* that
> "!x" === "x!=0". I don't see how this could be any clearer.
> > The spec fragments above don't address how the boolean test is
> > coerced. Does it cast pointer to an integer and perform the test, or
> > does it cast the 0 to a pointer and perform the test. The C++ spec I
> > have is vague on this point. The only reference it makes to pointers
> > is that the operand for ! may be a pointer.
> Because of the equivalence *given in the text of* we can simply
> follow the money. (I'm not concerned, here, about what ambiguities the
> C++ folks may or may not have introduced into their monstrosity. The
> Linux kernel is written in C, and the C standard is unambiguous on this
> point. Though frankly I'd be suprised if C++ breaks something so
> straightforward and useful.)
> The section that defines != says
> 6.5.9 Equality operators
> Syntax
> (1) equality-expression:
> relational-expression
> equality-expression == relational-expression
> equality-expression != relational-expression
> Constraints
> (2) One of the following shall hold:
> ...
> -- one operand is a pointer and the other is a null pointer constant.
> (5) ... If one operand is a pointer and the other is a null pointer
> constant, the null pointer constant is converted to the type of the
> pointer. ...
> So:
> 1. !x is defined equivalent to x!=0.
> 2. 0 is a "null pointer constant".
> 3. (assuming x is a pointer) 0 will be promoted to pointer type in the
> expression "x!=0".

You are right to 99.9% ;)

The last 0.1% of wrongness comes from linux/stddef.h:
#define NULL ((void *)0)

Thus, !ptr is equivalent to ptr==0 but not equivalent to ptr==NULL
in general case for the kernel code (it is equivalent if ptr is
a variable of a _pointer type_ because ptr then implicitly converted
to (void*)).

Our NULL isn't 0 by design. it's not a bug, regardless what Stroustrup says
about NULL define.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-08-15 09:54    [W:0.090 / U:0.652 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site