Re:The Ten Commandments for C Programmers (1987)
by illuminated on Saturday May 23, 2020 @10:46AM
(#23283372)
Instead of the second, I'd rather put: "Thou shalt understand pointers, before using them"
[ Parent
| on HN ]
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.
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
Re:The Ten Commandments for C Programmers (1987)
by gigatexal on Saturday May 23, 2020 @11:02AM
(#23283485)
Can you program in C effectively without pointers?
Re:The Ten Commandments for C Programmers (1987)
by illuminated on Saturday May 23, 2020 @11:07AM
(#23283535)
Nope, therefore you cannot do it effectively if you do not understand them :)
Re:The Ten Commandments for C Programmers (1987)
by klyrs on Saturday May 23, 2020 @11:19AM
(#23283614)
Depends on what you mean by "effectively." If you wanna, say, do an exhaustive search over all 4-dimensional integer vectors in a rectangular region, and print off the ones that satisfy some relationship, you don't need pointers (nevermind what printf and string literals are doing under the hood). It's a wonderfully beefy desktop calculator, in that way. But for most applications, pointers are pretty much necessary.
Re:The Ten Commandments for C Programmers (1987)
by WalterBright on Saturday May 23, 2020 @05:23PM
(#23286591)
Arrays in C (once passed to functions) are pointers, even when they use array syntax: