Re:A Reply to “Let’s stop copying C”
by TheCoelacanth on Sunday January 26, 2020 @12:11AM
(#22150498)
Not in cases where the optimizer did something tricky based on the assumption that null pointer dereferences never happen (which is allowed because they are undefined behavior so any behavior is correct).
Re:A Reply to “Let’s stop copying C”
by WalterBright on Sunday January 26, 2020 @01:20AM
(#22150705)
I'm aware of those, but don't implement them in my compilers. It's not worth it.
Oh wow, I didn't know you were on here! I'm a huge fan of D so I just wanted to say thanks for all the work you've done. D is an absolute pleasure to work with.
Re:A Reply to “Let’s stop copying C”
by WalterBright on Sunday January 26, 2020 @12:57PM
(#22153493)
Thanks for the kind words!
You didn't but I remember a case where Linux's devs got bitten by gcc which did it..
This does not save you if that null pointer is supposed to point to an array, and subsequent index operations move it out of the protected first page (or the first couple, I forget how modern Unix does it).
This is indeed how certain language runtimes generate null pointer exceptions. It would be too slow to add comparisons against null to every use of a pointer. So they handle SIGSEGV and raise the exception if the faulting access is on the null page.
Interesting side question: if you have a struct bigger than a page, and you dereference the end of it... How big does it have to be to not get this behavior?
Re:A Reply to “Let’s stop copying C”
by WalterBright on Sunday January 26, 2020 @12:04AM
(#22150482)
That's a great question. The best way to find out is to write a program that pokes every 4k until you find the boundary.
Yes, it's undefined behavior, but in reality you get a null pointer seg fault on systems with memory protection.