lkml.org 
[lkml]   [2004]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Use NULL instead of integer 0 in security/selinux/
From
Date
On Jul 10, 2004, Linus Torvalds <torvalds@osdl.org> wrote:

> On Fri, 9 Jul 2004, Eric W. Biederman wrote:
>>
>> Does this mean constructs like:
>> ``if (pointer)'' and ``if (!pointer)'' are also outlawed.

> Of course not.

> 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?

> What's considered bad form is:
[snip]
> - thinking the constant "0" is a pointer.

> There's no reason why "if (!ptr)" would be wrong.

[6.5.3.3]/#5 defines the result of the logical negation operator
based on the result of comparing the expression with 0.

> But it has nothing to do with the _value_ zero, or testing pointers for
> being non-NULL. The value zero is not about semantic confusion, it's just
> a bit pattern. And testing pointers is not ambiguous: when you test a
> pointer, it's _un_ambigiously checking that pointer for NULL.

I don't see why (!ptr) is any more confusing than (ptr != 0), and why
(ptr != NULL) would be any clearer. Is `ptr != 0' one of the cases
that are not bad?

--
Alexandre Oliva http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:04    [W:0.283 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site