Thread: 'NULL' : undeclared identifier

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Question 'NULL' : undeclared identifier

    When working with pointers when I use separate files (and sometimes when I use 1 file) I get:

    error C2065: 'NULL' : undeclared identifier

    I did some searching but none of these worked:

    Code:
    #define NULL
    Code:
    #define NULL 0
    Code:
    #define NULL ((void *) 0)
    Code:
    #ifndef NULL
    #ifdef __cplusplus
    #define NULL    0
    #else
    #define NULL    ((void *)0)
    #endif
    #endif
    Code:
    #include <cstdlib>
    In fact, compiling using any these usually crashes the program.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well actually, IIRC, you don't even need NULL for anything in C++, since it just evaluates to zero. And defining NULL as zero isn't what makes your program crash. It's your program doing something it shouldn't elsewhere. Like running off the end of an array, dereferencing null pointers, etc etc.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM