4 ms·
> Thou shalt not follow the NULL pointer How much pain and misery could be avoided if hardware manufacturers would simply design computers so that memory locat
by lisper 16y ago
> Thou shalt not follow the NULL pointer
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.
- pornel 16y agoThat 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).
- lisper 16y ago> That doesn't work if you expect struct or array Ah, good point.
- dinkumthinkum 16y agoWhat exactly do you think that would solve?
- jws 16y agoIt handily converts your buggy pointer traversal code from SEGFAULT to infinite loop.
- swolchok 16y agoWhy 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.
- Seth_Kriticos 16y agoEver heard of sarcasm?
- palish 16y agoI was sarcastic once.
- jpablo 16y agoWouldn't that be worse ? Instead of a coredump you'll get subtle and hard to track errors.
- barrkel 16y agoPresuming 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.
- meastham 16y agoEven 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 http://pastie.org/1278260. You may have to alter /proc/sys/vm/mmap_min_addr and/or your SELinux policy.
- Locke1689 16y agohttp://en.wikipedia.org/wiki/Virtual_memory http://en.wikipedia.org/wiki/Virtual_memory