1

Related: Eclipse CDT "Symbol NULL could not be resolved"

I was under the impression that NULL was a standard macro in C++ and didn't need any headers to be included. Eclipse, on the other hand, thinks it doesn't exist.

Is there some way to remind Eclipse that I'm in C++ mode not C mode for this file, and therefore to shut up about the NULL problem?

Community
  • 1
  • 1
Chris Browne
  • 1,582
  • 3
  • 15
  • 33

2 Answers2

9

I was under the impression that NULL was a standard macro in C++.

It is, but it's not part of the language. You still need to include <cstddef> or <cstdlib>, etc.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
3

Why is NULL undeclared?

Quoted from the top-answer on that question.

NULL is not a built-in constant in the C or C++ languages. In fact, in C++ it's more or less obsolete, just use a plain literal 0 instead, the compiler will do the right thing depending on the context.

Otherwise, add

#include <stddef.h>

to get the NULL definition.

UPDATE: I had the wrong header, corrected now. Thanks! (Quoted from Unwind)

Community
  • 1
  • 1
Sephallia
  • 396
  • 2
  • 9