🔒 Locked
'NULL' : undeclared identifier
Advertisement
Original Post
NULL is a #define in some headers, it is not built into any compiler. The most lightweight way is to copy it from a standard header into your own header. For example:
[edited by - foofightr on July 15, 2003 5:46:10 AM]
// the almighty NULL, shamelessly ripped from windef.h
#ifndef NULL
# ifdef __cplusplus
# define NULL 0
# else
# define NULL ((void *)0)
# endif
#endif
[edited by - foofightr on July 15, 2003 5:46:10 AM]
are you sure that example has no headers included?
also what compiler and libraries are you using?
also what compiler and libraries are you using?
#include <cstddef> or just use 0 instead.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
i tried exactly that and it came up with:
Compiling...
null.cpp
c:\work\sand\xor\null.cpp(4) : error C2065: ''NULL'' : undeclared identifier
I have VC6.0 SP5
are you sure there are no includes (such as stdafx.h) or anything else?
Compiling...
null.cpp
c:\work\sand\xor\null.cpp(4) : error C2065: ''NULL'' : undeclared identifier
I have VC6.0 SP5
are you sure there are no includes (such as stdafx.h) or anything else?
I can''t believe that code is compiling.
Try compiling using ctrl-f7
Is it included in the project? Can you run it? If so place a breakpoint in the code. Rebuild it with browse information, right click on NULL and choose go to definition - what does it give you?
Try compiling using ctrl-f7
Is it included in the project? Can you run it? If so place a breakpoint in the code. Rebuild it with browse information, right click on NULL and choose go to definition - what does it give you?
or use neither.. if (ptr) instead of if (ptr!=NULL) or if (!ptr) instead of if (ptr==0)... wont make it any more readable but you can be even more lazy. btw. stroustrup himself recommends to use 0 instead of NULL for fewer problems or at least defining it as const int and not via #define.
someone looking at the code should be able to recognize a pointer even without having any NULL around if you name your variables correctly.
someone looking at the code should be able to recognize a pointer even without having any NULL around if you name your variables correctly.
I just prefix my variable names with "p" for pointers (Hungarian notation).
[ Bananas | My dead site | www.sgi.com | Goegel ]
[ Bananas | My dead site | www.sgi.com | Goegel ]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement