Indrek Rebane wrote:
Hey folks,
Russell Nelson wrote:
Even if there was a good reason to change it, there's way too
much code that does this kind of thing:
foo = malloc(10); if (!foo) exit(1);
Which is a really bad programming practice. After all, ain't unary
logical operations with pointers illegal? Better way would be:
if (foo == NULL)
Which gives nice int value to if for evaluation in C (bool in C++).
Indrek
Let's put it this way: Having used 'C' compilers on at least 11
different architectures (MSP430, AVR, x86, AM29000, 8051, 68xx, 68xxxx,
VAX, Z80, 80196, SH/3) by at least as many compiler vendors, it's never
been a problem. And GCC, which has pretty darn good rule checking with
-W -Wall doesn't complain. Can't say I remember what lint in strict
mode might recommend.
Two of the more common constructs in C are: "if (!index ("this",
"is") ..." and "if (!(ptr = malloc (12)))..." If it's illegal, well
over 50% of the software ever written is wrong.
I recollect a vague discussion years ago that on one particular
machine, NULL wasn't 0 or some variant of 0. Obviously, that machine
survived time so well, I can't even recall what it was. And there was
at least a few machines that had special hardware exception handlers it
you tried to write to 0.
So it's pretty much a moot point. In Idealland (about 20km north of
Utopia), everyone might compare to NULL. But it ain't gonna happen.
--jc