RE: Re: Managing accidental read/writes to addresszero
"Randall Young" <[email protected]>
| Newsgroups | gmane.comp.hardware.motorola.microcontrollers |
|---|---|
| Message-ID | <[email protected]> |
> You can't redefine NULL,
Actually that's not true. There is nothing in either the ANSI or ISO
standards that forbids redefining the preprocessor macro NULL. It's not on
the list of pre-defined macros that cannot be redefined, and in fact is a
"standard language addition", meaning you do not *have* to use the
definition that comes with the compiler at all.
> it is *defined* by the language to be "0" in a
> pointer context,
Also not true, the macro NULL is not guaranteed to have a particular value
in *any* context.
> the compiler then turns it into whatever it's internal
> representation of a null pointer is (which may or may not be a valid
> memory location, and may not be location 0)
Every C implementation I've ever used has either #define NULL 0 or #define
NULL ((void *)0). There is unfortunately a lot of legacy code in the world
that assumes (NULL == 0) is a true expression. It's not good code, it's
non-portable and tends to be confusing, but it exists and any compiler that
breaks it will likely be considered to have a bug (in spite of what the
standards say).
> See http://www.eskimo.com/~scs/C-faq/s5.html, esp Qs 5.2, 5.4, and for
> people like me (hardware enigneers who hack C occasionally) 5.15!
The author of that page is clearly confused ... apparently he does not
remember that C is case-sensitive. The sections he quotes as saying that
NULL is the same as 0 uniformly say that a pointer assigned to be 0 is null,
which is not the same thing at all ! Except for the one that says "... null
pointer constants, *usually* referred to by the name NULL ...". Note the
implication that there can be multiple null pointer constants ...
However, the whole "redefining NULL" discussion misses the point. The main
issue is that pointers *which have never been initialized* are frequently 0.
Thus, dereferencing an uninitialized pointer (rather than one that has been
deliberately initialized to NULL) is the real problem the OP is trying to
address.
Randall Young
Senior Software Engineer
NavCom Technology, Inc.
A John Deere Company
-----------------------------------------------------------
To learn more about Freescale Microcontrollers, please visit
http://www.freescale.com/mcu
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/MPC500/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/