From: Denis Vlasenko <vda@ilport.com.ua>
To: Andy Isaacson <adi@hexapodia.org>, Marc Singer <elf@buici.com>
Cc: Marcel Holtmann <marcel@holtmann.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] spi
Date: Mon, 15 Aug 2005 10:51:13 +0300 [thread overview]
Message-ID: <200508151051.13678.vda@ilport.com.ua> (raw)
In-Reply-To: <20050809192920.GC23389@hexapodia.org>
> > 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
next prev parent reply other threads:[~2005-08-15 7:51 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-10 20:01 [PATCH 3/3] kconfig: linux.pot for all arch Egry Gábor
2005-08-08 9:12 ` [PATCH] spi dmitry pervushin
2005-08-08 10:41 ` Jiri Slaby
2005-08-08 13:16 ` Mark Underwood
2005-08-08 16:41 ` dmitry pervushin
2005-08-08 18:51 ` Mark Underwood
2005-08-08 14:55 ` Greg KH
2005-08-08 17:35 ` Marcel Holtmann
2005-08-08 17:47 ` Marc Singer
2005-08-09 17:54 ` Andy Isaacson
2005-08-09 19:05 ` Marc Singer
2005-08-09 19:29 ` Andy Isaacson
2005-08-15 7:51 ` Denis Vlasenko [this message]
2005-08-08 22:58 ` Andrew Morton
2005-08-10 13:10 ` Pavel Machek
2005-08-08 23:07 david-b
2005-08-09 9:38 ` Mark Underwood
2005-09-26 11:12 SPI dmitry pervushin
2005-09-27 12:43 ` SPI Greg KH
2005-09-27 14:27 ` [spi-devel-general] SPI dmitry pervushin
2005-09-27 14:35 ` Greg KH
2005-09-27 14:49 ` dmitry pervushin
2005-09-27 14:54 ` Greg KH
2005-09-28 13:14 ` [PATCH] SPI dmitry pervushin
2005-09-30 17:59 David Brownell
2005-09-30 18:30 ` Vitaly Wool
2005-09-30 19:20 ` dpervushin
2005-10-03 4:56 David Brownell
2005-10-03 5:01 David Brownell
2005-10-03 6:20 ` Vitaly Wool
2005-10-03 16:26 David Brownell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200508151051.13678.vda@ilport.com.ua \
--to=vda@ilport.com.ua \
--cc=adi@hexapodia.org \
--cc=elf@buici.com \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®