Thread: comparing memory spaces. is it possible?

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    8

    comparing memory spaces. is it possible?

    hi guys i want to do the following code but it wont work

    Code:
    if(history[0][1] == NULL)
       printf("this worked");
    basically what i want it to do is if the array history[0][1] has nothing in it (which i thought meant null) then i want want to do something. the compiler keeps giving me an error that i can use binary operators on history[0][1].

    p.s the history array is of type struct history_entry which i have defined my self.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    A test against NULL is a test used for pointers, to see if they point at something. So, unless you have a two dimensaional array of pointers, the test is invalid.


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

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    How did you define history in the first place?
    Did you initialise it?
    Is history an array of pointers (NULL is for the 'empty' pointer)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    C has no value which represents a lack of a value. In short, this means that there is no way to check if an object does not have a value because it always does. You might need to rewrite your program based on this new tidbit of knowledge.

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    8
    alright thanks guys i just initialized the part of the structure im comparing to NULL and it solved the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  3. Copying memory, pointers and the like.
    By psychopath in forum C++ Programming
    Replies: 34
    Last Post: 12-12-2006, 01:37 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM