Re: [PATCH] Use NULL instead of integer 0 in security/selinux/

From: Linus Torvalds
Date: Sat Jul 10 2004 - 01:19:56 EST




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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/