That's basically what null pointers do. The problem isn't "dereferencing a null pointer", the problem is dereferencing an INVALID pointer. Null pointers minimize the danger, by having programmers follow the practice that every pointer must be either valid, or null. That way, if that practice is followed, you can simply compare a pointer to NULL, and if it compares unequal, then you can safely dereference it.>>61107709
Does the existence of a null pointer address mean that the address space is 1 byte smaller than calculated? i.e. with 32 bit pointers = 2^32 byte = 4 GiB address space. But since one address has to be reserved for the null pointer, isn't the usable memory actually 4 GiB minus 1 byte?>>61107778>The only way I know to treat a physical object as "not logically present" is with some kind of extra bool field, enum field, or similar. (For example: "bool exists;")
Perhaps in a linked-list implementation, if it's only going to store positive integer values (and you don't need the range provided by unsigned), you could perhaps use a negative integer as an end-of-list sentinel value. Though that wouldn't be compatible if you want to use your linked list to store other types.>>61107935
Hoare, not Hawk. He's the guy that invented quicksort.