C and C++ could have non_nullable pointers, easily
C and C++ could have non_nullable pointers, easily
Posted Sep 9, 2009 6:59 UTC (Wed) by cmccabe (guest, #60281)In reply to: C and C++ could have non_nullable pointers, easily by nix
Parent article: Null pointers, one month later
In higher level languages like OCaml, Java, etc., when you encounter an unrecoverable error in a function, you throw an exception. Then the function has no return value-- control just passes directly to the relevant catch() block.
ERR_PTR is the same thing. Normally, the function would return a foo pointer, but an unrecoverable error happened. So you get an error code instead. As a bonus, if you forget to check for the error code, you get a guaranteed crash (well, if some bonehead hasn't allowed the page starting at address 0 to be mapped). I say "bonus" because the alternative is usually a nondeterministic crash.