Jump to content
  • Advertisement
Sign in to follow this  
exa_einstein

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

This topic is 5062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
class Null
{

public:

template <typename TYPE>
operator TYPE*() const
{
return 0;
}

};

const Null null;

GravityObjectSystem::GravityObjectSystem()
{
aDescriptiveName = 0;
anotherDescriptiveName = null;
}

Simple, clean, unambiguous.

Enigma

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
If I'm not mistaken, stddef.h always defines it. Of course, as Namethatnobodyelsetook mentioned, 0 is the correct C++ equivalent.

Share this post


Link to post
Share on other sites
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 once
test.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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!