This is the mail archive of the gcc-patches@gcc.gnu.org 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: [C++ patch] accept __null as sentinel


Richard Henderson wrote:
FWIW, Michael, I agree that allowing NULL (and thus __null) to be used
as a valid sentinal is the only way this will practically be useful to
real code.

I agree.


But Joseph's not saying that we should somehow break the code; just that it's OK for us to warn about passing NULL to a varargs function, on the grounds that code does that is unportable.

To me, an important question is whether there are systems where passing NULL to varargs doesn't work. The warning is only useful if we're warning about portability problems that might occur in practice, rather than in theory. For example, we don't warn about converting an extern "C" function pointer to an extern "C++" function pointer because, although the standard says those *might* have different calling conventions, there has never been a system on which they actually did.

I think the answer is that there are systems on which this is a potential problem. For example, on Solaris 2.8, /usr/include/mon.h does "#define NULL 0", even for 64-bit compilation.

The actual code is:

#ifndef NULL
#if defined(_LP64) && !defined(__cplusplus)
#define NULL    0L
#else
#define NULL    0
#endif
#endif

So, for C++ compilation on 64-bit system, you'll get the "#define NULL 0" case, if you're not using GCC. The HP-UX 11.11 omp.h header seems to have similar definitions. And, I've certainly seen code where people put "#define NULL 0" directly into their code.

So, I think we can conclude that code that passes NULL to a varargs function is indeed unportable, not just in theory, but in practice. But, of course, a warning isn't useful to people who will only be compiling with G++, or for code where NULL is known to be defined to a safe value.

So, I think we should continue to warn for this use of __null -- but provide a -Wno-... flag to shut that up. I think having it be part of -W, but not -Wall, might make sense.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304


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