tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: definition of NULL correct?
On Tue, Aug 11, 2009 at 7:14 PM, Valeriy E.
Ushakov<uwe%stderr.spb.ru@localhost> wrote:
> My reading of footnote 71 is that gcc gets the precedence right.
>
> 71)The syntax specifies the precedence of operators in the
> evaluation of an expression, which is the same as the
> order of the major subclauses of this subclause, highest
> precedence first. Thus, for example, the expressions
> allowed as the operands of the binary + operator (6.5.6)
> are those expressions defined in 6.5.1 through 6.5.6.
> The exceptions are cast expressions (6.5.4) as operands
> of unary operators (6.5.3), [...]
>
> sizeof is unary expression - 6.5.3, cast is 6.5.4. The exception
> mentioned is for the production:
>
> unary-expr: unary-operator cast-expr
>
> and doesn't apply to sizeof. So
>
> sizeof (void *) 0
>
> is correctly parsed as uanry-expr: sizeof ( type-name ) leaving the
> "0" as the syntax error.
>
> Neat. I was always bothered by lack of parens around that cast and
> always wondered if there is a context where it gonna bite us...
>
make sense, any objection to fix NULL definition ?
--- a/sys/sys/null.h
+++ b/sys/sys/null.h
@@ -5,7 +5,7 @@
#ifndef NULL
#if !defined(__GNUG__) || __GNUG__ < 2 || (__GNUG__ == 2 &&
__GNUC_MINOR__ < 90)
#if !defined(__cplusplus)
-#define NULL (void *)0
+#define NULL ((void *)0)
#else
#define NULL 0
#endif /* !__cplusplus */
- Arnaud
Home |
Main Index |
Thread Index |
Old Index