User forums > Help

NULL undefined

(1/8) > >>

JaR:
Hello,
I just realized, that, in the following code, the compiler returns an error, because of NULL being undefined. Is this a bug within the gcc, should CB define the macro itself or is it just not defined in standard C++?


--- Code: ---int main ()
{
  int n = NULL;
  return 0;
}
--- End code ---

if i #include <iostream> first, there is no problem.

JaR

XayC:
NULL is not part of the C or C++ *, but it's usually defined in some headers.
So yes you have to define it, and it's not a Gcc bug.


--- Code: ---#define NULL 0                   // C++ definition.
#define NULL ((void*)0)          // C definition.

--- End code ---

Edit: * With "not part of the C or C++" I mean not a language keyword. It does not mean you have to define it, because it's defined in the standard headers.

Regards, XayC

JaR:
Thanks for the quick reply.
Edit: I think the definition is not supposed to have a semicolon.

JaR

Seronis:

--- Quote from: JaR on September 15, 2007, 11:22:55 am ---Edit: I think the definition is not supposed to have a semicolon.
--- End quote ---
Correct.  That will make the semicolons themselves be part of the text replace the preprocessor performs.  That aside id also use a global const int and not a define.  Then again I'm also anal retentive about type issues.  =-)

XayC:

--- Quote from: JaR on September 15, 2007, 11:22:55 am ---I think the definition is not supposed to have a semicolon.

--- End quote ---
Yes you are right: edited. Thanks for pointing it out.

Navigation

[0] Message Index

[#] Next page

Go to full version