Thread: pointer warnings

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    pointer warnings

    I get these warnings with each corresponding line. How do I get rid of them?

    62 C:\projects\spacedout\midi.c
    [Warning] comparison between pointer and integer

    if(midi->device_handle == NULL)

    68 C:\projects\spacedout\midi.c
    [Warning] assignment makes integer from pointer without a cast

    midi->device_handle = NULL;
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >midi->device_handle
    Are you sure that this is a pointer?
    My best code is written with the delete key.

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    more liklely to be an integer.

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Then am I suppose to change NULL to 0? I thought NULL is 0.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    11
    Then am I suppose to change NULL to 0? I thought NULL is 0.
    NULL is more likely to be (void*)0. But if the variable is an int you should use 0, if it's a pointer you should use NULL. It's a bad idea to try and use NULL in any context other than pointers.

  6. #6
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    Code:
    if(midi->device_handle == NULL)
    Yes, that is a pointer. "midi" is the address of a structure, and "device_handle" is a field in the structure. Which also happens to be the address of a structure for a device record.

    Since it is a pointer, you must use "(void*)0L", to explicitly tell the compiler to ignore the coercion/cast.

    If necessary make a headerfile for yourself with your own global defines, and do something like this:

    Code:
    #define   NIL  (void*)0L
    That makes sure that you have a value that is zero across all bits of the native word, and can be used with pointers.

    enjoy.
    It is not the spoon that bends, it is you who bends around the spoon.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  3. Warnings with Pointer In Linked List
    By charIie in forum C Programming
    Replies: 8
    Last Post: 12-27-2007, 05:18 PM
  4. scope of a pointer?
    By Syneris in forum C++ Programming
    Replies: 6
    Last Post: 12-29-2005, 09:40 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM