[c++] warn if NULL is passed through varargs

Fergus Henderson fjh@cs.mu.OZ.AU
Thu Oct 10 10:14:00 GMT 2002


On 10-Oct-2002, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Oct 10, 2002, Michael Matz <matz@suse.de> wrote:
> 
> > A compiler (or library header) which defines NULL for C (which has to be a
> > pointer) to just 0 on such a machine is broken.
> 
> grep '#define NULL' /usr/include/*.h reveals a number of programs that
> define NULL to 0, at least when NULL isn't previously defined, which
> is possible if you #include say <expect.h> or <tcl.h> before
> <stddef.h>.
> 
> Of course, such mis-definitions wouldn't take any benefit from the
> warnings in the first place, since the warning could only possibly
> trigger if gcc gets to define NULL the way it can track where it's
> used inappropriately.

The warning would catch some of these cases -- in particular, it could
catch the ones where NULL is misused in a header file that is included
in two compilation units, one of which includes <expect.h> or <tcl.h> first
and one of which doesn't.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.



More information about the Gcc-patches mailing list