Null object: Difference between revisions

m
Line 37:
* Point to something that has no value to the programmer.
 
 
We can choose quite a few places, the easiest one I can think of is <code>$FFFF</code>. Although it sort of breaks our first rule, as when dereferenced as a 16-bit value, you get the value stored at <code>$0000</code> as the high byte, we still can access <code>$0000</code> normally anyway. Since it points to the high byte of the interrupt request vector, it's something we don't want to (or most likely can't) modify at runtime, and is of no use to us (if we really wanted the IRQ handler's address we'd dereference <code>$FFFE</code> instead.)
 
How a null pointer is implemented is very simple. You decide beforehand what your null pointer will be, and before you dereference a pointer variable, compare it to the null pointer, and if they're equal, don't dereference it. That's all there is to it.
1,489

edits