WTF??!! NULL is not defined in MSVC60??!!

Started by
106 comments, last by null_pointer 19 years, 8 months ago
I tried to compile a system of some nested classes and what happenned.. (small code dump:)


// in header file of the class

class gravityobjectsystem:public spaceobject
{
	spaceobject* soa;
	int nso;
public:
	gravityobjectsystem();
	virtual ~gravityobjectsystem();

///...........
// and then in .cpp file ...

gravityobjectsystem::gravityobjectsystem()  //constructor
{
	nso=0;
	soa=NULL;
}
//....
I thought that this sholdn't be a problem, but MSVC6.0 came with two errors: error C2065: 'NULL' : undeclared identifier //??????!!!!!! error C2440: '=' : cannot convert from 'int' to 'class spaceobject *' does somebody had any similar problem? I though NULL is valid zero pointer really EVERYWHERE? ISN'T??!! WTF?!!! helpme... (i don't want to #define my own NULL) exa_einstein
When I was younger, I used to solve problems with my AK-47. Times have changed. I must use something much more effective, killing, percise, pernicious, efficient, lethal and operative. C++ is my choice.
Advertisement
Just use 0 (zero). Seriously
I know this, but question here is a little more about that "Has the NULL disappeared?" bug in visualC? (I have really checked everything)

ok,ok. now I use soa=(spaceobject*)0; because soa doesn't look like normal integer with it...
When I was younger, I used to solve problems with my AK-47. Times have changed. I must use something much more effective, killing, percise, pernicious, efficient, lethal and operative. C++ is my choice.
NULL is #defined or whatnot in various library headers. If you don't include any of these in your project, then NULL is just an undeclared identifier. If you really want you can always add
#ifndef NULL#define NULL 0#endif
to your code, although switching to simply using 0 might be just as good. Only a few rare systems using something other than 0 for NULL. I'd switch, but I'm too lazy at the moment. Actually, if it's a big enough project, I'd probably just make my own const variable that matched the naming convention of the rest of my constants, and was in the proper namespace, too, if I was using namespaces.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
class Null{	public:		template <typename TYPE>		operator TYPE*() const		{			return 0;		}};const Null null;GravityObjectSystem::GravityObjectSystem(){	aDescriptiveName = 0;	anotherDescriptiveName = null;}

Simple, clean, unambiguous.

Enigma
Quote:Original post by Enigma
*** Source Snippet Removed ***
Simple, clean, unambiguous.

Enigma


nice
Actually, you'll have to define your own NULL - because it's normal definition place is in the windows.h headers (or one hanging off that).

Enigma: Sweet [wink]
If I'm not mistaken, stddef.h always defines it. Of course, as Namethatnobodyelsetook mentioned, 0 is the correct C++ equivalent.
Then why is there the line:

#define NULL ((void *)0)

in windows.h?
Hi,

Quote:Original post by exa_einstein
I thought that this sholdn't be a problem, but MSVC6.0 came with two errors:

error C2065: 'NULL' : undeclared identifier //??????!!!!!!
error C2440: '=' : cannot convert from 'int' to 'class spaceobject *'

does somebody had any similar problem? I though NULL is valid zero pointer really EVERYWHERE? ISN'T??!! WTF?!!!


You thought wrong. NULL is *not* defined everywhere. One of these days, try to compile the following code:

int main() {  void* ptr = NULL;  return 0;}


I just did, and GCC gave me the following:

test.c: In function `main':test.c:2: `NULL' undeclared (first use in this function)test.c:2: (Each undeclared identifier is reported only oncetest.c:2: for each function it appears in.)


That is because NULL is not a symbol defined by default, but is contained in stdlib.h. (And also happens to be defined in windows.h, and some other headers.)

Vovan
Vovan

This topic is closed to new replies.

Advertisement