| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pointers |
From: rbs{at}snippets.org
To: c_echo{at}yahoogroups.com
On Mon, 8 Sep 2003, Jerry Coffin wrote:
> > True. The standard only says that there will be a value called NULL,
> > which will be defined in a macro which will be found in the stddef.h
> > file. It does not specify what value will be specified by NULL. It
> > is generally zero, and I have never heard of it being anything else,
> > but still, implementation defined is implementation defined, and not a
> > strict standard.
>
> Not so -- the macro NULL is required by the standard to have the value
> zero -- the only part that's implementation defined is what type it is
> (e.g. char, short, int, long, void *, etc.)
This is tricky stuff... By my understanding, this is an asymmetrical
conversion - according to 6.3.2.3,
"An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.) If a null pointer
constant is converted to a pointer type, the resulting pointer, called a
null pointer, is guaranteed to compare unequal to a pointer to any object
or function.
Conversion of a null pointer to another pointer type yields a null pointer
of that type. Any two null pointers shall compare equal.
An integer may be converted to any pointer type. Except as previously
specified, the result is implementation-defined, might not be correctly
aligned, might not point to an entity of the referenced type, and might be
a trap representation.)
Any pointer type may be converted to an integer type. Except as previously
specified, the result is implementation-defined. If the result cannot be
represented in the integer type, the behavior is undefined. The result
need not be in the range of values of any integer type."
So if you cast the integer 0 to a pointer you get a null pointer constant,
i.e. NULL. However, if you cast a null pointer constant to an integer, the
results are implementation-defined. It is *implied* that casting NULL to
an integer should yield 0, but support in the standard for that assumption
is shaky. In practical terms, almost everyone depends on it and its
failure would break a *lot* of existing code, but it's not required, as I
understand it.
-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/
Web graphics development: http://Image-Magicians.com/
Software archives: http://snippets.org/snippets/
Audio and loudspeaker design:
http://LDSG.snippets.org/
http://www.diyspeakers.net/
--- SoupGate-Win32 v1.05
* Origin: rbs{at}snippets.org (2:292/516.666)SEEN-BY: 633/267 270 @PATH: 292/516 854 140/1 106/2000 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.