Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 (Tek) 9/26/83; site orca.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!orca!andrew
From: andrew@orca.UUCP (Andrew Klossner)
Newsgroups: net.unix-wizards
Subject: Re: new topic...exorcising externs
Message-ID: <887@orca.UUCP>
Date: Sat, 9-Jun-84 16:33:29 EDT
Article-I.D.: orca.887
Posted: Sat Jun  9 16:33:29 1984
Date-Received: Sun, 10-Jun-84 07:05:44 EDT
References: <311@zeus.UUCP> <2515@allegra.UUCP>
Organization: Tektronix, Wilsonville OR
Lines: 31

[]

	"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@rand-relay)  [ARPA]