RE: nullable pointers
Posted Mar 31, 2011 13:21 UTC (Thu) by
HelloWorld (guest, #56129)
In reply to:
RE: nullable pointers by neilbrown
Parent article:
GCC 4.6.0 released
But when you really want a nullable pointer, as you do in a linked list or any tree data structure
You don't need nullable pointers for linked lists
abstract class List<T> { }
final class ListNil<T> { }
final class ListCons<T> { T elem; List<T> tail; }
or for trees
abstract class BinaryTree<T> { }
final class TreeNil<T> { }
final class TreeCons<T> { T elem; BinaryTree<T> left; BinaryTree<T> right; }
arbitrarily not allowing one seems pointless.
What is arbitrary is a null reference, not the lack of it. What could be more arbitrary than a magical value created out of thin air, which is a value of (almost) every type, yet supports none of the operations that all other values of these types support.
(
Log in to post comments)