[comp.lang.c] dpANS C and `static' functions

chris@mimsy.UUCP (Chris Torek) (12/29/87)

In article <136@ateng.UUCP> chip@ateng.UUCP (Chip Salzenberg) writes:
>[Some existing compilers already require the first declaration of a
static function to include the keyword `static', i.e.,
	f() { g(); }
	static g() {
is illegal.]

>I like it.  For example, on the '286 in "large model", static functions
>could be made "near", thus improving performance and reducing stack usage.

Static functions could indeed be made near . . . but if and only if
the compiler first looks at entire source files, in which case the
whole reason for making `static wins' illegal goes away.  Consider
the following:

	% cat file1.c
	static int f() { return (3); }	/* a silly function */

	p() {
		... = f();		/* this can use a near call */
	}

	int (*sneaky())() {
		return (f);
	}
	% cat file2.c
	extern int (*sneaky())();
	main() {
		int (*fn)();
		fn = sneaky();
		... = (*fn)();		/* but this cannot */
	}
	%

The problem is the same as that of inlining functions at compile
(rather than link) time.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris