new topic...exorcising externs

John P. Linderman jpl at allegra.UUCP
Fri Jun 8 23:30:26 AEST 1984


There are a number of situations where externals are both cleaner and
more convenient than parameter passing.  One instance that comes to mind
is "errno".  I wouldn't hold it up as the paradigm of clean design,
but it beats passing a pointer to an error value to every system call.
Another favorite of mine is to declare an external
    char *Progname;
and then do
    Progname = argv[0];
or
    Progname = p = argv[0];
    while (*p) if (*p++ == '/') Progname = p;
in the main routine to set Progname to the name (or basename) of the
command as it was invoked.  Being external, the name is available to
diagnostic routines without having to be passed around.  This eliminates
the problems of building the command name into the command (suppose it
gets linked or installed under a different name) and encouraging the
use of the command name in all error diagnostics (don't you just love
it when you run a pipeline of commands and one of them prints:
    malloc failed.
and then dies without identifying itself?  It would almost be better
if it missed the check and dropped a core, so you could run a "strings"
on the core and find out who it was.)

John P. Linderman  Department of External Affairs  allegra!jpl



More information about the Comp.unix.wizards mailing list