[LLVMdev] [cfe-dev] Style question: NULL or 0?

Christopher Jefferson chris at bubblescope.net
Thu Aug 18 01:03:48 PDT 2011


On 18 Aug 2011, at 01:23, David Blaikie wrote:

>> using NULL gives you a false sense of security - which isn't entirely
>> true now that compilers (GCC & clang
>> presumably) will warn you about using NULL in non-pointer contexts.
> 
> Hmm, nope, can't seem to find that warning in clang - gcc gives it though:
> 
> foo.cpp:4:11: warning: converting to non-pointer type "int" from NULL

For the curious, the way that gcc does this is by doing:

#define NULL __null

and then treating __null as 0 in all ways, except for the purposes of warning tracking. clang already encapsulates __null as GNUNullExpr, so in principle (although beyond me) it shouldn't be hard to add warnings, wherever it gets converted to an integer.

Chris



More information about the llvm-dev mailing list