Re:The Ten Commandments for C Programmers (Annotated Edition)
by jpablo on Saturday November 06, 2010 @02:19PM
(#1877411)
Wouldn't that be worse ? Instead of a coredump you'll get subtle and hard to track errors.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by barrkel on Saturday November 06, 2010 @03:50PM
(#1877610)
Presuming the CPU takes it into account in addressing modes (so that e.g. [EAX + EDX * 4 + 13], like you might see when accessing a field of an element in an array, still returns 0 if EAX is 0), you'd stil have problems similar to non-signalling NaNs vs signalling NaNs: you want the problems associated with a bug to be localized to where the bug is, and not leak out. When the bad value escapes into other code and causes problems down the line, it can be hard to figure out where the value came from.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by pornel on Saturday November 06, 2010 @01:58PM
(#1877373)
That doesn't work if you expect struct or array at 0.
IMHO a better solution is to have a type system that has non-NULLable types, and/or use language that inserts NULL checks automatically (and optimizes them away where they're redundant).
Re:The Ten Commandments for C Programmers (Annotated Edition)
by lisper on Saturday November 06, 2010 @02:07PM
(#1877393)
> That doesn't work if you expect struct or array
Ah, good point.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by dinkumthinkum on Saturday November 06, 2010 @02:01PM
(#1877378)
What exactly do you think that would solve?
Re:The Ten Commandments for C Programmers (Annotated Edition)
by jws on Saturday November 06, 2010 @02:14PM
(#1877404)
It handily converts your buggy pointer traversal code from SEGFAULT to infinite loop.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by swolchok on Saturday November 06, 2010 @04:33PM
(#1877695)
Why is that good? It also doesn't solve:
int *p = malloc(LOTS);
int v = read_from_network();
int o = read_from_network();
p[o] = v;
if that malloc fails, for example.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by Seth_Kriticos on Saturday November 06, 2010 @06:20PM
(#1877908)
Ever heard of sarcasm?
Re:The Ten Commandments for C Programmers (Annotated Edition)
by palish on Saturday November 06, 2010 @06:55PM
(#1877974)
I was sarcastic once.
Re:The Ten Commandments for C Programmers (Annotated Edition)
by meastham on Saturday November 06, 2010 @07:58PM
(#1878134)
Even if this were desirable, it would make much more sense for the OS (or C library) to do it rather than have it enforced by the hardware.
(edit) or, you could do it yourself. The following works for me on Linux: http://pastie.org/1278260. You may have to alter /proc/sys/vm/mmap_min_addr and/or your SELinux policy.
How much pain and misery could be avoided if hardware manufacturers would simply design computers so that memory location 0 was hard-wired to always contain a 0.
Sigh.