Marc-O
Marc-O

Reputation: 711

Use NULL or nullptr for a C++ null pointer?

I am trying to make some Clang AST-dumps on dummy tests files. This is the command line I am using :

 clang -Xclang -ast-dump -fsyntax-only test.cpp

int * a = NULL; is recognized for my test.c, but not for my test.cpp.

I also tried int * a = nullptr; but that does not work aswell.

Should I change some options in my command line ?

Upvotes: 0

Views: 3048

Answers (3)

Fish
Fish

Reputation: 1265

Just use 0.

int *a = 0;

nullptr was introduced only in C++11. Pass the option -std=c++11 to your compiler. Does your version of clang support C++11? Regarding NULL see here.

Upvotes: 0

paxdiablo
paxdiablo

Reputation: 881403

C++ prior to C++11 allowed either NULL (if you included the cstddef header file) or 0 itself.

I tend to prefer NULL because of my C background and I want to plainly see the difference between a null pointer and a zero value. However, some people prefer to just use 0.

The introduction of nullptr in C++11 solved some problems, including which overloaded function to call when given a null pointer (one that takes an integer, or one that takes a pointer).

Upvotes: 2

codekiddy
codekiddy

Reputation: 6137

use this command line: clang -std=c++11 -Xclang -ast-dump -fsyntax-only test.cpp

now you can use nullptr

OR

#include <cstddef>

now you can use NULL

otherwise use 0

Upvotes: 5

Related Questions