Re: union and overstamping zero values
andrew_nuss@yahoo.com wrote:
Not portably. The NULL pointer need not to be represented
by a bit pattern that also represents the zero integer
If so, then why does this work?:
main {
void* p = 0;
if (p == 0)
p = malloc(2000);
if (p)
free(p);
}
I have chosen to use zero with pointers rather than the #define NULL
according to some recommendation that I saw once upon a time.
This is because the compiler makes provisions for this since the
language does (I don't know specifically where, I just know it does).
A void * being assigned 0 (NULL) or used as a test (NULL = FALSE, else
TRUE) has long historical reasons and would break a lot of code if not
implemented as such. So NULL does not necessarily mean all bits 0, but
the compiler makes it appear to be so.
Adrian
--
_____________________________________________________________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ _---_ Q. What are you doing here? _---_ /
\ / | A. Just surf'n the net, teaching and | \ /
\__/___\___ learning, learning and teaching. You?_____/___\__/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]