ANSI X3J11 onexit() implementation

Doug Gwyn gwyn at brl-smoke.ARPA
Wed Jun 18 07:10:44 AEST 1986


I have just posted a public-domain implementation of the ANSI X3J11
(draft C language standard) "onexit" function to net.lang.c (INFO-C),
as I promised during the last couple of weeks.  The main purpose is
to help implementors who thought that this would be too much trouble
and were therefore objecting to onexit().

As a result of actually implementing this function, I am now in a
position to criticize the interface.  In the May 1, 1986 Draft
standard (X3J11/86-074), the new defined type "onexit_t" is used in
two different contexts: as the return value type of the user's
pre-termination function and as the value returned by onexit() to
indicate success or failure of function registration.  The former
usage should certainly be (void), since there is no way to make use
of any value that a pre-termination function might return.  The
latter usage need only be a simple (int), but the current Draft
states that it must be comparable to a NULL pointer constant, which
unfortunately the Draft has strongly indicated should be (void *)0
instead of the traditional 0.  A much cleaner interface would be:

	int onexit(void (*func)(void));

which would return zero or not depending on whether the function
was successfully registered.  I think the current awkward design is
an artifact of the original Whitesmiths, Ltd. implementation which
required each pre-termination function to return a pointer to the
next most recently registered function, so that exit() could
traverse the list of function pointers without having to maintain
private storage for them.  However, that's not necessary under the
current design, so I would like to see the interface cleaned up.



More information about the Comp.lang.c mailing list