Re: Definition of NULL
From: Keith Thompson (kst-u_at_mib.org)
Date: 11/16/04
- Next message: Swami Tota Ram Shankar: ">>> TERRORIST AND EVIL ANGLO-SAXON RACE AND RELIGION <<< FACTS YOU WONT HEAR"
- Previous message: Dave Vandervies: "Re: Learning C from old books ??"
- In reply to: Gordon Burditt: "Re: Definition of NULL"
- Next in thread: Malcolm: "Re: Definition of NULL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 16 Nov 2004 22:28:02 GMT
gordonb.5d4rz@burditt.org (Gordon Burditt) writes:
[...]
> The internal representation (bit pattern) of a NULL is not specified.
> It is *NOT* guaranteed to be 0xdeadbeef, not even on 32-bit machines.
> But if the internal representation is 0xdeadbeef,
> p == 0
> must be true if p contains a NULL pointer. If that means generating
> assembly-language code to compare p to the bit pattern 0xdeadbeef, so
> be it.
>
> However, neither
> memset((void *)&p, 0, sizeof(p));
> nor
> memset((void *)&p, 0xdeadbeef, sizeof(p));
> is guaranteed to set p to a NULL pointer.
The latter almost certainly won't, even if a null pointer is
represented as 0xdeadbeef. The second argument to memset() is
converted to unsigne char. On system with CHAR_BIT==8, this will most
likely (or certainly, but I'm too lazy to track the chapter(s) and
verse(s)) give you 0xef (the low-order 8 bits). If sizeof(p) is 4,
the value stored in p is going to be 0xefefefef.
(If CHAR_BIT==32, it should assign 0xdeadbeef to p, but that would be
an unusual system.)
Again, null pointers are explained quite well in section 5 of the
C FAQ (google "C FAQ"). There's little point in rehashing the
explanations here.
-- Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst> San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.
- Next message: Swami Tota Ram Shankar: ">>> TERRORIST AND EVIL ANGLO-SAXON RACE AND RELIGION <<< FACTS YOU WONT HEAR"
- Previous message: Dave Vandervies: "Re: Learning C from old books ??"
- In reply to: Gordon Burditt: "Re: Definition of NULL"
- Next in thread: Malcolm: "Re: Definition of NULL"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|