From: Linus Torvalds <torvalds@osdl.org>
To: Alexandre Oliva <aoliva@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Chris Wright <chrisw@osdl.org>,
akpm@osdl.org, linux-kernel@vger.kernel.org, sds@epoch.ncsc.mil,
jmorris@redhat.com, mika@osdl.org
Subject: Re: [PATCH] Use NULL instead of integer 0 in security/selinux/
Date: Sat, 10 Jul 2004 21:40:13 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0407102128490.1764@ppc970.osdl.org> (raw)
In-Reply-To: <orhdsfo75w.fsf@livre.redhat.lsd.ic.unicamp.br>
On Sat, 10 Jul 2004, Alexandre Oliva wrote:
>
> > Why should they be?
>
> Err... Because the conditional expression is implicitly compared with
> 0 [6.8.4.1]/#2. If 0 is not to be used explicitly in pointer
> contexts, why should it be ok to use it implicitly?
Exactly BECAUSE it's not an explicitly WRONG type of 0.
"0" is a number token. It is totally illogical from a conceptual
standpoint to use it as a pointer. It makes no sense from any syntactic
standpoint, and it's very much an ugly special case because K&R didn't
want to add a keyword for NULL.
But the fact is, even early on, exactly _because_ "0" is illogical as a
pointer, K&R added a
#define NULL 0
to make it make _syntactic_ sense to use "NULL" as a pointer, even though
the language lacked the specific keyword. So from a _syntactic_
standpoint, NULL is a pointer, even if from an implementation standpoint
NULL ended up being this totally illogical integer 0.
In contrast, there is nothing syntactically strange about comparing a
non-boolean (even though Pascal and other languages make it illegal). So
here again, the "compare against 0" is an _implementation_ issue, not a
conceptual syntactic confusion.
What I object to in using "0" as a pointer is that it changes the meaning
of the token "0" depending on semantic information that may not even be
very local. In contrast
if (ptr)
..
has no such confusion.
> [6.5.3.3]/#5 defines the result of the logical negation operator
> based on the result of comparing the expression with 0.
And you're totally confusing the "this is defined to be equivalent" as an
implementation standpoint with "it's the same thing".
For example, the code
5[ptr]
is _defined_ to be exactly the same as
ptr[5]
since they both really mean
*(ptr + 5)
and nothing else. HOWEVER, despite the fact that the C language _defines_
that they are exactly equivalent, I claim that anybody who writes "5[ptr]"
is an ass.
For that same reason, your argument is totally irrelevant. Yes,
if (ptr)
is _defined_ to be exactly the same as
if (ptr != 0)
but I claim that anybody who writes the latter is an ass, because it makes
no syntactic sense. The same way "5[ptr]" doesn't make syntactic sense,
even though the compiler will silently accept it.
Got it?
Linus
next prev parent reply other threads:[~2004-07-11 4:41 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-07 19:25 Chris Wright
2004-07-08 3:12 ` Herbert Xu
2004-07-08 3:27 ` David S. Miller
2004-07-08 3:43 ` Miles Bader
2004-07-08 5:22 ` Linus Torvalds
2004-07-08 5:35 ` Miles Bader
2004-07-08 15:58 ` Linus Torvalds
2004-07-08 16:23 ` Dave Jones
2004-07-08 17:57 ` Geert Uytterhoeven
2004-07-09 11:23 ` Roman Zippel
2004-07-10 19:41 ` Geert Uytterhoeven
2004-07-11 10:29 ` Geert Uytterhoeven
2004-07-11 10:54 ` viro
2004-07-11 16:14 ` Linus Torvalds
2004-07-11 20:05 ` H. Peter Anvin
2004-07-12 15:58 ` Florian Weimer
2004-07-12 16:34 ` H. Peter Anvin
2004-07-08 11:18 ` Herbert Xu
2004-07-08 13:10 ` Andreas Schwab
2004-07-08 13:56 ` Herbert Xu
2004-07-08 14:13 ` Andreas Schwab
2004-07-08 5:19 ` Linus Torvalds
2004-07-08 16:09 ` Timothy Miller
2004-07-08 16:21 ` Linus Torvalds
2004-07-08 16:27 ` Linus Torvalds
2004-07-08 16:52 ` Timothy Miller
[not found] ` <200407090056.51084.vda@port.imtp.ilyichevsk.odessa.ua>
2004-07-12 15:17 ` Timothy Miller
2004-07-12 16:12 ` Andreas Schwab
2004-07-12 16:51 ` Andrew Pimlott
2004-07-15 16:15 ` Timothy Miller
2004-07-09 20:36 ` Eric W. Biederman
2004-07-09 23:49 ` Paul Jackson
2004-07-10 1:43 ` Kyle Moffett
2004-07-10 1:47 ` Herbert Xu
2004-07-10 21:53 ` Alexandre Oliva
2004-07-10 6:18 ` Linus Torvalds
2004-07-10 6:23 ` Linus Torvalds
2004-07-10 6:58 ` Andrea Arcangeli
2004-07-10 9:48 ` Eric W. Biederman
2004-07-10 15:39 ` Roland Dreier
2004-07-11 2:45 ` Eyal Lebedinsky
2004-07-11 21:19 ` Olaf Titz
2004-07-10 9:39 ` Eric W. Biederman
2004-07-10 9:56 ` Herbert Xu
2004-07-11 21:47 ` Olaf Titz
2004-07-13 8:43 ` Geert Uytterhoeven
2004-07-14 3:12 ` Alexandre Oliva
2004-07-13 18:53 ` Elladan
2004-07-14 3:15 ` Alexandre Oliva
2004-07-10 12:11 ` Roman Zippel
2004-07-10 21:59 ` Alexandre Oliva
2004-07-11 4:40 ` Linus Torvalds [this message]
2004-07-10 9:31 ` Eyal Lebedinsky
2004-07-10 22:07 ` Alexandre Oliva
2004-07-10 23:52 ` Paul Jackson
2004-07-11 0:12 ` Tim Wright
2004-07-12 22:03 ` Bill Davidsen
2004-07-10 8:18 ` Florian Weimer
2004-07-08 11:10 ` Richard B. Johnson
2004-07-08 11:28 ` Michael Buesch
2004-07-08 11:44 ` Martin Zwickel
2004-07-08 12:06 ` Michael Buesch
2004-07-08 12:38 ` [OT] NULL versus 0 (Re: [PATCH] Use NULL instead of integer 0 in security/selinux/) Kari Hurtta
2004-07-08 12:42 ` Michael Buesch
2004-07-08 12:57 ` Kari Hurtta
2004-07-08 15:25 ` Herbert Xu
2004-07-10 8:22 ` [PATCH] Use NULL instead of integer 0 in security/selinux/ Florian Weimer
2004-07-08 11:43 ` P. Benie
2004-07-08 14:32 ` Richard B. Johnson
2004-07-08 15:00 ` Michael Poole
2004-07-08 15:30 ` P. Benie
2004-07-08 15:55 ` Andreas Schwab
2004-07-10 7:09 ` Andrea Arcangeli
2004-07-10 7:02 ` Andrea Arcangeli
2004-07-10 6:59 ` Andrea Arcangeli
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=Pine.LNX.4.58.0407102128490.1764@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=akpm@osdl.org \
--cc=aoliva@redhat.com \
--cc=chrisw@osdl.org \
--cc=ebiederm@xmission.com \
--cc=herbert@gondor.apana.org.au \
--cc=jmorris@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mika@osdl.org \
--cc=sds@epoch.ncsc.mil \
/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®