| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Pointers |
From: jcoffin{at}taeus.com
To: c_echo{at}yahoogroups.com
At 08:41 AM 9/8/2003 -0500, you wrote:
[ ... ]
>"An integer constant expression with the value 0, or such an expression
>cast to type void *, is called a null pointer constant.)
Note, however, that the "null pointer constant" is italicized here -- that
means this is the definition of a null pointer constant.
The other relevant bit is 7.17/3 (or 7.1.6 in the old standard) that says:
NULL
which expands to an implementation-defined null pointer constant.
Since we have the definition above, we can just substitute it in almost
like a macro and get the standard's requirement:
NULL expands to an implementation-defined integer constant
expression with the value 0, or such an expression cast to type void *
As such, the value is not implementation defined -- only the type, and the
exact text of the expression that has the value 0. Obvious possibilities
are 0, 0L and (void *)0. Less obvious but still legitimate would be things
like (9-9) or ('1'-'0'-1) or a nearly infinite collection of other constant
expressions, though none of them really accomplishes anything, since the
result always has to be zero anyway.
>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.
A null pointer constant is required to have the value 0, and NULL is
required to be a null pointer constant, so it must also have the value
0. Once you take that null pointer constant and assign it to an actual
pointer, you're absolutely correct -- an asymmetric conversion can take
place, so if you convert the result _back_ to an integer, the result may be
non-zero.
This is NOT the case with the macro itself though -- it _has_ the value 0
to start with. The only tricky part is if it's 0 cast to pointer to void;
in that case, even though we know it has the value 0, it could be
impossible to actually retrieve that value (though somehow this starts to
remind me of the old question of whether a tree falling in the forest makes
any sound if there's nobody there to hear it).
Later,
Jerry.
--- SoupGate-Win32 v1.05
* Origin: jcoffin{at}taeus.com (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™.