jacobnavia <
[email protected]> writes:
Le 15/04/2020 à 05:05, Thimble Liu a écrit :
I don't understand how a integer constant 0 cast to void *, can
result a tree which op is CNST+P, and u.v.p field equal to NULL.
I think that if you write:
char *p = 0x40407865;
You are making a pointer out of a constant. That wouldn't be the NULL
pointer since its value would be different from zero, hence the second condition.
Right. Expanding on that a bit, the C standard defines a "null
pointer constant" as "An integer constant expression with the value
0, or such an expression cast to type void *". So
char *p = 0;
sets p to a null pointer value, and
char *p = (char*)0x40407865;
sets p to some implementation-defined value (almost certainly not a null pointer), but
int zero = 0;
char *p = (char*)zero;
doesn't necessarily set p to a null pointer value. It *probably*
will (and lcc might even guarantee it), but the the language
doesn't guarantee it, because there is no null pointer constant.
(Even "const int zero = 0;" wouldn't make `zero` or `(char*)zero`
a null pointer constant.)
Note that I'm only talking about what the C standard says. I know
practically nothing about lcc internals. lcc, I'm fairly sure,
represents a null pointer as all-bits-zero, which is the case for all
or almost all actual compilers but is not required by the language.
--
Keith Thompson (The_Other_Keith)
[email protected]
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)