Re:The Ten Commandments for C Programmers (1987)
by pm215 on Saturday May 23, 2020 @11:15AM
(#23283587)
The second item is warning against a particular misuse of pointers that was apparently widespread at the time. On VAX Unix, it happened that the memory at address zero of a process was readable and contained zeroes. So a lot of code would misuse a NULL pointer as being equivalent to a pointer-to-an-empty-string, for instance: worked fine on the VAX!. So it's kind of a specific flavour of commandment 10. These days the common machines don't have a readable address zero, and all the old non-portable code has faded into history.
[ Parent
| on HN ]
Re:The Ten Commandments for C Programmers (1987)
by bnjf on Saturday May 23, 2020 @02:41PM
(#23285321)
right. compat for this still exists on solaris at least, as lib0@0: see the notes section at the bottom of [0].
[0] - https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7md6/inde...
Re:The Ten Commandments for C Programmers (1987)
by burfog on Sunday May 24, 2020 @12:50AM
(#23289187)
That could enable optimization. The compiler could remove many NULL-pointer checks.
On many platforms, all that is required is a change to the compiler. It could emit a ".quad 0" or equivalent, in a common data section at absolute address zero. Some platforms would require linker changes or even kernel changes.
Re:The Ten Commandments for C Programmers (1987)
by asveikau on Saturday May 23, 2020 @11:52AM
(#23283933)
16-bit x86 also had the interrupt handler table at linear address 0, I seem to recall some compilers for DOS that would make NULL point at that.
Re:The Ten Commandments for C Programmers (1987)
by oriolid on Saturday May 23, 2020 @02:25PM
(#23285180)
Yes. At least writing to interrupt vector table usually crashed your computer right at the point. I remember a certain DSP architecture that system flags near zero address. It was an interesting experience to debug a program that failed because a write to struct member through null pointer switched the machine to a different instruction set.
Re:The Ten Commandments for C Programmers (1987)
by kevin_thibedeau on Saturday May 23, 2020 @01:02PM
(#23284532)
Every MMU-less micro lets you read address 0.
Re:The Ten Commandments for C Programmers (1987)
by monocasa on Saturday May 23, 2020 @01:46PM
(#23284880)
A lot of micros have MPUs that'll catch address 0 accesses without a full MMU. AFAIK all ARMs newer than ARM7 (ie. ARMv5) have one for instance.
Re:The Ten Commandments for C Programmers (1987)
by RealityVoid on Saturday May 23, 2020 @04:43PM
(#23286237)
Yeah, they will, if you activated it. And if you made access to 0 address be caught explicitly ( you might have the MMU active but not have it configured in such a way)
Re:The Ten Commandments for C Programmers (1987)
by illuminated on Saturday May 23, 2020 @02:24PM
(#23285168)
Yes, I know and I agree, I just said I'd rather put a more broad message there