Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 'NULL' undeclared...

This thread is locked; no one can reply to it. rss feed Print
'NULL' undeclared...
Denis Sinner
Member #4,278
January 2004

I Wrote a class which includes an pointer to the next Object of the same class. It worked fine. Then i tried to place the class in it's own header h. + .cpp file. Now when i'm trying to compile, i'm getting the following error:(I'm Using Dev cpp)

`NULL' undeclared (first use this function)

(I'm using NULL in the constructor for the pointer to the next Object)

Chris Katko
Member #1,881
January 2002
avatar

Include a standard header perhaps?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Korval
Member #1,538
September 2001
avatar

I would venture the following guess. One of the .cpp files that includes the .h file includes it before including anything else (like <stdlib.h> and so forth). You should include your standard library headers first.

Radagar
Member #2,768
September 2002
avatar

I know this makes a difference with Visual Studio, but I'm not sure about DevCpp.

Try renaming the .h file to .hpp

NULL is not declared in C, but is in C++, if I remember correctly.

------------
Radagar - So your vote is for A.D.H.D.?
Chris Katko - Well, that was uninten--ooh kitty!

Zaphos
Member #1,468
August 2001

You could just do:

#ifndef NULL
#define NULL 0
#endif

Radagar: NULL is declared in standard header files. I'm not sure why .h -> .hpp would do anything at all ... it sounds silly.

Billybob
Member #3,136
January 2003

I'm wondering why no one ranted yet... [url http://www.allegro.cc/forums/view_thread.php?_id=331783]

23yrold3yrold
Member #1,134
March 2001
avatar

Yeah, I was about to link that :)
Almost certianly, that's his problem.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Chris Katko
Member #1,881
January 2002
avatar

Quote:

Radagar: NULL is declared in standard header files. I'm not sure why .h -> .hpp would do anything at all ... it sounds silly.

He didn't include any standard header files first off, secondly there's a difference between c and cpp files.

And ofcourse, read the link.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Zaphos
Member #1,468
August 2001

Quote:

He didn't include any standard header files first off, secondly there's a difference between c and cpp files.

I know both these things, I've read the link (before reading this thread, actually), and your post has no relevance whatsoever to what you quoted.

Chris Katko
Member #1,881
January 2002
avatar

The "And ofcourse, read the link." part was for the OP.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Surt
Member #273
April 2000
avatar

NULL is declared in <stddef.h> under C and <cstddef> under C++.

---
--
-

Go to: