new topic...exorcising externs
Andrew Klossner
andrew at orca.UUCP
Sun Jun 10 06:33:29 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."
The "well structured" approach would be to define a small module (aka
package) with entry points as follows:
void seterrno(i) int i;
/* called by system routines to record an error number */
int geterrno()
/* returns the last parameter to seterrno, 0 if none */
Now you do your system calls as follows:
if (open(...) == -1) {
printf("open error %d\n", geterrno());
}
Presto, no externals, just a single static within the errno module.
This would make a lot more sense if the loader supported more than just
a flat global name space, a la Modula II.
-- Andrew Klossner (decvax!tektronix!orca!andrew) [UUCP]
(orca!andrew.tektronix at rand-relay) [ARPA]
More information about the Comp.unix.wizards
mailing list