Re: [PATCH] spi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > 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.  6.5.3.3 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 6.5.3.3* 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.
--
vda

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux