Abandon NULL for (0)
James Shankland
jas at postgres.uucp
Fri Sep 22 14:35:03 AEST 1989
In article <146 at bbxsda.UUCP> scott at bbxsda.UUCP (Scott Amspoker) writes:
>Professionally, I cast everything - makes lint real happy.
Actually, in most cases, lint couldn't care less. It is a fallacy that
the degree of portability of your code varies directly with the number
of casts in it. Casts are conversions whose semantics are, in many
cases, implementation-dependent.
>At home I use 0 for a null pointer. I test pointers with expressions
>like:
> if (pointer)... /* at home */
> if (!pointer)...
Stylistically a little dubious, in my opinion, but certainly widely
practiced. Also entirely safe.
>as opposed to
>
> if (pointer!=(char *)0) /* at work */
>
>Modern C compilers are quite reliable about this ...
Modern C compilers will reliably generate warnings on this if `pointer'
has any type other than `char *'. Modern C compilers will be
entirely happy if you leave out the cast, provided `pointer' is any
scalar or pointer type.
jas
More information about the Comp.lang.c
mailing list