[comp.lang.c] NULL function pointers

Leisner.Henr@Xerox.COM (Marty) (09/14/87)

K&R guarantees pointers to valid data objects are non-NULL.  But what
about function pointers?  I found no reference to guarantees to non-NULL
function pointers and a number of compiler system/linkers I've seen have
no problem inserting C functions at address 0.

It seems like a good idea not to have  a valid function at address NULL so it
is easy to test a function pointer for validity.

On MS-Dos, for instance, a signal handler at the top of your program
(address 0) will often cause problems for signal() (at least with aztec
C).



marty
GV:  leisner.henr
NS:  martin leisner:henr801c:xerox
UUCP: martyl@rocksvax.uucp

 

guy@sun.uucp (Guy Harris) (09/15/87)

> K&R guarantees pointers to valid data objects are non-NULL.  But what
> about function pointers?  I found no reference to guarantees to non-NULL
> function pointers and a number of compiler system/linkers I've seen have
> no problem inserting C functions at address 0.

The passage in question says "object", not "data object", and only a cad of an
implementor would interpret "object" as meaning "data object" here.  (Of
course, it is quite possible that some C implementors *are* cads; the
existence of systems that do not ensure that no function has an address that
compares equal to a null pointer would suggest that some are....)

The latest ANSI C draft says "object or function" in its discussion of null
pointers, thus restraining the aforementioned implementors and ensuring that C
implementations are sane in this regard.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com (or guy@sun.arpa)