Skip to main content
gamedev.net
🔒 Locked

Problem with NULL

Started by TheRealBartman Apr 27, 2003 at 6:53 PM 16 replies 2.3k views
Original Post
TheRealBartman
TheRealBartman
Sometimes, almost at random, some of the files in my projects give me errors about NULL being undefined, while other files compile just fine. Why is this, and is there anyway to fix it without doing #define NULL 0x000000 in every affected source file? Thanks, Michael Bartman
Michael BartmanLead ProgrammerDark Omen Studios
Gee
Gee
Well NULL is not a C nor a C++ keyword, so of course you need to define it. Just include stdio, iostream, windows.h and NULL will ultimately be defined...

---
General Programmer at Wildfire Games
working on the 0 A.D. project
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Beer Hunter
Beer Hunter
#include any of <clocale>, <cstddef>, <cstdio>, <cstdlib>, <cstring>, <ctime>, <cwchar>.
Arild Fines
Arild Fines
Or use 0...



"Laughter means distance. Where laughter is absent, madness begins. The moment one takes the world with complete seriousness one is potentially insane. The whole art of learning to live means holding fast to laughter; without laughter the world is a torture chamber, a dark place where dark things will happen to us, a horror show filled with bloody deeds of violence."
-- Jens Bjørneboe
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
TheRealBartman
TheRealBartman
Thanks for the replies

I would just use 0, and even though it is shorter to write than NULL, I am more partial to using NULL.

It is just a preference of mine.

Michael Bartman
Michael BartmanLead ProgrammerDark Omen Studios
Irrelevant
Irrelevant
Your preference is wrong.
zealouselixir
zealouselixir
NULL has a standard value, according to the C++ standard. But, the implementation is still responsible for defining it in a standard manner. I personally use 0 to indicate null-ness. One might think that NULL helps clarify that it''s actually a null pointer, but in my experience, it doesn''t.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
RhoneRanger
RhoneRanger
Okay, let me start it.....


Is NULL different than 0?

Techlead
www.myran.com/enilno
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Zipster
Zipster
0 isn''t typesafe? What?
Beer Hunter
Beer Hunter
quote:
Original post by Anonymous Poster
The 0 or NULL argument. Run! Oh... and neither is typesafe.
Joking, I assume?
Ready4Dis
Ready4Dis
quote:
Original post by RhoneRanger
Okay, let me start it.....


Is NULL different than 0?

Techlead
www.myran.com/enilno


I don''t beleive NULL is allowed to be anything besides 0, but don''t hold me to that, as it may be up to the implementation to decide. In any compiler/platform I''ve EVER seen, NULL has always been defined as 0.
Chris-
Chris-
quote:
Original post by Ready4Dis
[quote]Original post by RhoneRanger
Okay, let me start it.....


Is NULL different than 0?

Techlead
www.myran.com/enilno

I don't beleive NULL is allowed to be anything besides 0, but don't hold me to that, as it may be up to the implementation to decide. In any compiler/platform I've EVER seen, NULL has always been defined as 0.



in the C standard, NULL is (void *)0
in the C++ standard, NULL is 0

When programming in C++, Bjarne says NULL is naughty, stick to trusty 0.



[edited by - Chris- on April 28, 2003 2:31:33 AM]
TheRealBartman
TheRealBartman
Argh lol,

Okay, I won''t use NULL anymore.

Why did it come about, anyway?


Michael Bartman
Michael BartmanLead ProgrammerDark Omen Studios
RhoneRanger
RhoneRanger
null is (void*) 0, which is different than just
''0''

''0'' still is a number, while NULL literally nothing!
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Peon
Peon
Interesting thread, I had no idea. I always used NULL; looks like it''s time to change my ways
Peon
Cedric
Cedric
quote:
Original post by RhoneRanger
null is (void*) 0, which is different than just
''0''

null is not Standard C++. NULL is 0.

Cédric
PHRICTION
PHRICTION
Quoth Stroustrup:

In C, it has been popular to define a macro NULL to represent the zero pointer. Because of c++''s tighter type checking the use of plain 0, rather than any suggested NULL macro, leads to fewer problems. If you feel you must define NULL, use

const int NULL = 0;

The const qualifier prevents accidental redefinition of NULL and ensures that NULL can be used where a constance is required.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.