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

Alexandre Oliva aoliva@redhat.com
Wed Oct 9 11:46:00 GMT 2002


On Oct  9, 2002, "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> wrote:

> I reread the discussion agin and I can't tell if anyone is proposing
> to *also* include this warnings for C.  (FWIW I think that's a bad
> idea.)

Some people have proposed it, and I actually think it's a good idea,
except that I'm not sure it should be enable it by default as it is in
C++.

The point is that there are no guarantees in C that NULL is as wide as
a pointer.  Compare that with C++, in which you're pretty much
guaranteed that NULL will *not* be as wide as some pointer types,
since pointers-to-members have different widths than regular
pointers.

Even though GCC currently defines NULL to (void*)0, which guarantees
it's as wide as a pointer, there's no guarantee that if you
va_arg(list, char*) (or any other pointer type, for that matter),
you'll get a NULL value back, since the representation of void* could
be different form that of any other pointer type.

So GCC would be doing a favor to the user by recommending a type cast
to the intended pointer type in C, just like it currently does in C++
(except in the varargs case, that the patch fixes).

Which of these arguments do you disagree with?  Or, which
counter-arguments can you bring into this debate?

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer



More information about the Gcc-patches mailing list