lkml.org 
[lkml]   [2004]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Use NULL instead of integer 0 in security/selinux/


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?

What's considered bad form is:
- assignments in boolean context (because of the confusion of "=" and
"==")
- thinking the constant "0" is a pointer.

There's no reason why "if (!ptr)" would be wrong. That has zero confusion
about 0 vs NULL.

The confusion about "0" is that in traditional C it means two things: it
can either be an integer (the common case) or it can sometimes be a
pointer. That kind of semantic confusion is bad.

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.

Problems arise when there is room for confusion, and that's when the
compiler should (and does) warn. If something is unambiguous, it's not
bad.

Linus

-
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: 2009-11-18 23:46    [W:0.161 / U:1.028 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site