Thread: i havent done C in a very long time.. null help

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    221

    i havent done C in a very long time.. null help

    where is null defined?
    if its not defined, how can i go about making my own null to use with pointers?

    i thought null was defined as (void*)0 or (void*)&0
    or something like that

    thanks for the help!

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    :/usr/include$ grep -r "#define NULL" *
    g++-3/streambuf.h:#define NULL (__null)
    g++-3/streambuf.h:#define NULL (0)
    linux/stddef.h:#define NULL 0
    linux/stddef.h:#define NULL ((void *)0)
    mysql/mysql_com.h:#define NULL_LENGTH ((unsigned long) ~0) /* For net_store_length */
    pth.h:#define NULL (void *)0
    rpc/clnt.h:#define NULLPROC ((u_long)0)
    rpc/xdr.h:#define NULL_xdrproc_t ((xdrproc_t)0)

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005

    Re: i havent done C in a very long time.. null help

    >where is null defined?

    Perhaps you mean NULL.
    http://www.eskimo.com/~scs/C-faq/q5.4.html

    >if its not defined, how can i go about making my own null to use with pointers?

    Don't. Use NULL or 0.

    You may want to review null pointers.
    http://www.eskimo.com/~scs/C-faq/s5.html
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Feb 2004
    Posts
    79
    revelation.

    null, nul and NUL are'nt defined. NULL of course is.

    I generally consider null, nul and NUL to be '\0' whilst NULL is ((void *)0)

    Take a peek in stdio.h you may find it's been defined there.
    It may also be defined in other various locations.
    R.I.P C89

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    The C language defines a macro, NULL, that is the equivalent of 0 in pointer context. Past that it's all individual terminology, but many people make the following distinctions:

    null, NULL - A pointer that points to nothing
    nul, NUL - The '\0' character

    In the end they all evaluate to 0 though.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Virtual Printer" or "Moving Printjobs"
    By extasic in forum Windows Programming
    Replies: 12
    Last Post: 06-30-2011, 08:33 AM
  2. Compiling 3rd party code problem me too
    By siavoshkc in forum C Programming
    Replies: 1
    Last Post: 09-12-2007, 05:55 AM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  4. Problem with a menu.
    By Rare177 in forum Windows Programming
    Replies: 4
    Last Post: 09-07-2004, 11:51 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM