[cfe-dev] Fixing selector types on the GNU runtime

David Chisnall csdavec at swansea.ac.uk
Tue Jan 20 17:46:57 PST 2009


On 21 Jan 2009, at 01:35, Mike Stump wrote:

> On Jan 20, 2009, at 4:51 PM, David Chisnall wrote:
>> I can't find a copy of the spec online (and I leant my paper copy  
>> to someone a while ago), but every reference I can find says that  
>> NULL may be a #define for 0 or 0L.
>
> Fine, but this is irrelevant to the question at hand.  The question  
> at hand is an internal implementation detail of a particular  
> compiler, that compiler being g++ on FreeBSD.  They apparently  
> goofed.  That's a bug in FreeBSD, and it needs to be fixed.  Once  
> fixed, there is no issue here.

The question at hand is whether, according to the C++ spec, NULL, when  
passed to a variadic function, will always be a 0 pointer.  I can't  
find a single reference to support this.  If you have one, then it's a  
bug in g++ combined with the FreeBSD headers.  If you don't, then it's  
a fault in LLVM's usage of NULL, which happens not to matter on some  
platforms.

>> If NULL is #define'd to __null on some platforms, then this is  
>> great, but isn't it a GCC extension?
>
> I'd call it a private internal implementation detail of the  
> compiler.  The compiler is implemented such that for proper  
> operation, NULL _must_ be __null.

No, the compiler is implemented such that, for NULL to be a pointer  
when passed as an argument to a  variadic function it must be __null.   
Since the C++ spec appears to allow NULL to be 0 or 0L, for  
compatibility with C code and the C++ type system, this means that  
passing NULL as a pointer when it is an argument to variadic functions  
is either a special case in the spec or a GCC extension.

I have never heard of NULL having any special behaviour when passed as  
an argument to variadic functions (it is a preprocessor macro - the  
compiler shouldn't need to be aware of it at all after the source is  
preprocessed).  The fact that there is no such behaviour was cited as  
the main motivation for the introduction of one of the extensions  
added in C++0x.

>> I was under the impression that the LLVM coding conventions stated  
>> that GCC extensions were to be avoided so that it could be easily  
>> portable to compilers.
>
> llvm uses NULL.  NULL is not a gcc extension.

Totally irrelevant.  Once again, the question is whether NULL is  
guaranteed to be a type which will be passed as a pointer or a pointer- 
sized integer to variadic functions, not whether NULL is in the  
standard.

David



More information about the cfe-dev mailing list