This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Website patch: update projects to remove attribute nonnull

 > From: "Joseph S. Myers" <>
 > On Tue, 20 May 2003, Kaveh R. Ghazi wrote:
 > >  > I think it should be pointer to object typed zero only, not integers (for
 > >  > execl style).
 > > 
 > > Won't that break code using the NULL macro?  (Those whose
 > > implementations define it as an integer zero, usually 0 or 0L.)
 > Such code is broken because conforming implementations may use the integer
 > type: NULL cannot be used uncast as a variadic argument (and in principle
 > we could detect the use of the NULL macro in such a case and warn for it).
 > Thus the warning, detecting broken code with an uncast NULL (as was in an
 > example in a POSIX draft until the problem was pointed out and fixed), is
 > appropriate.

I know in the past there's been some disagreement on whether NULL
should be defined with (void*) type or not, but that's not relevant
here and I don't want to start a flame war about it.  I'm interested
in the practical application of this warning and whether people will
find it useful.

Let's speak in terms in surveying our own code.  On every single
platform on which gcc is supported, `NULL' works as a variadic
function terminator even if the function expects a pointer zero.  I
know this because we terminate uses of libiberty's concat with NULL
everywhere in gcc.  This works because every implementation takes care
to ensure the width of the NULL integer zero is the same width as a
pointer.  E.g. NULL is often "0L" on LP64 systems.

I don't think gcc is unique in its usage of NULL in this fashion.
Part of maiking warnings useful is to avoid spurious warnings.  IMHO,
warnings about NULL in this context are spurious, it would preclude
turning on this warning in -Wall for sure.  I agree we should warn if
someone uses a naked 0 and sizeof(int) != sizeof(void*), but that's an
actual bug.

Kaveh R. Ghazi

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]