[LLVMdev] [cfe-dev] Style question: NULL or 0?
David Blaikie
dblaikie at gmail.com
Wed Aug 17 17:22:00 PDT 2011
On Wed, Aug 17, 2011 at 4:41 PM, Jordy Rose <jediknil at belkadan.com> wrote:
> But I think I read somewhere that 0 is more C++esque.
I believe Stroustrup espoused this at one point (perhaps even on his
website) on the basis that 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.
> (And C++11 nullptr's not available yet, of course.)
My 2c is that this is a good reason to use NULL over 0 - it'll be way
easier to s/NULL/nullptr/ when upgrading to C++11 in the future than
it'll be to hunt down all those 0s used as pointers. Though I suppose
we can always enhance the compiler to warn about 0 used in pointer
contexts in C++11...
Hmm, we could do that today - hmm, is that something we should do? I
think it'd be rather neat/helpful - it could have a fixup & all that.
> 1. (x) and (!x)
This is my usual approach/preference.
Then you can also do things like:
if (T *x = foo())
...
More information about the llvm-dev
mailing list