9 ms·
> Wait, what? Why?! Who cares my value is wonky, why is my program giving an error? Just obtain the wonky value! (is what I thought when I first did it) Progra
by com2kid 6y ago
> Wait, what? Why?! Who cares my value is wonky, why is my program giving an error? Just obtain the wonky value! (is what I thought when I first did it)
Program on an MCU sometime, no memory protection. Feel free to tap dance all around RAM. It is rather liberating!
Really though, pointers are IMHO easy to understand, they are the address of an actual physical location in the real world. If you have a good enough microscope, or a large enough RAM chip, it would be possible to find the literal physical location that a pointer is referencing.
Pointers are the ultimate un abstraction. They represent something real!
- Gibbon1 6y agoThis here exactly. Dereferencing null. Oh maybe the compiler can figure out a pointer is null and try and ratfuck you in the name of some obscure 'optimization'. But when it can't what happens depends on the machine. Big iron machines with mmu's will invariably throw a seg fault. Some MCU's without an MMU will either seg fault because no physical memory exists[1] or return garbage. Some machines you get interesting things like the initial stack pointer. Or a memory mapped register. [1] Trapping seg faults and logging address of the offender takes most of the pain away.
- com2kid 6y agoThis is why MCUs are better. 0 is where memory starts, there is perfectly valid data at address 0. Pointers aren't the problem, NULL coloring pointers and the compiler tracking that, that is the problem. In a sane world '0' would be a perfectly valid address just like any other.