Is this a macro?

This is a discussion on Is this a macro? within the C Programming forums, part of the General Programming Boards category; I'm writing a bit of code using linked lists, and the statement... (struct node *) NULL keeps popping up all ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    98

    Is this a macro?

    I'm writing a bit of code using linked lists, and the statement...

    (struct node *) NULL

    keeps popping up all over the place.

    I would like to alias that as something else (e.g.) NNULL, so I tried...

    #define NNULL "(struct node *) NULL"

    then wrote

    if( head_node != NNULL )
    ...

    but the compiler said I couldn't compare a pointer to struct with a pointer to char, which is understandable.

    Do I need to write a macro to implement this... and if so, how do I do it.

    Thanks.

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>Well if you're writing in C (its on the C board)
    It's redundant in C++ too unless NULL is defined as (void *)0, then you'd get a warning about pointer conversions needing a cast. But since a bare 0 is implicitly converted to a null pointer in pointer context, you can avoid that problem by not using the NULL macro at all. :-)
    *Cela*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  4. Macro Program
    By daspope in forum Windows Programming
    Replies: 5
    Last Post: 04-25-2004, 04:02 AM
  5. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21