[net.bugs.4bsd] Undefined static function

guy@sun.uucp (Guy Harris) (06/23/85)

> Every declaration which is outside the definition of any function
> declares an extern static something, even with "extern" or "static"
> or both omitted.

False.  See 11.2 "Scope of externals":

	Identifiers declared "static" at the top level in external
	definitions are not visible in other files.

Any declaration outside the definition of any function with "static" omitted
declares an "extern" something, which is static in the sense of not being
"auto" but not static in the sense of being "static"; it's visible in other
files.

	Guy Harris

fdc@cstvax.UUCP (Frank Cringle) (06/24/85)

Here's a question for all the C language lawyers out there.  What should
a C compiler make of the following:

	static char *tgoto();

	main()
	{
		.....
		if (tgoto(......).....
		.....
	}

In other words, we declare a function to be static, use it, but do not
define it in the source file.  This occurs in libcurses/cr_tty.c (4.2BSD).
The 4.2 compiler happily accepts this and links the 'static' tgoto to a
definition in another source file.  In this case it is what the author
intended, but it should really have been thrown out by the compiler,
methinks.
-- 
Frank Cringle, Dept. of Computer Science, Univ. of Edinburgh
UUCP:  <UK>!ukc!{hwcs,kcl-cs,ucl-cs,edcaad}!cstvax!fdc
JANET: fdc@UK.AC.ed.cstvax  or   fdc@UK.AC.ed.ecsvax

adam@npois.UUCP (Adam V. Reed) (06/27/85)

Every declaration which is outside the definition of any function
declares an extern static something, even with "extern" or "static"
or both omitted.
				Adam Reed
				ihnp4!npois!adam

beal@polaris.UUCP (John L. Beal) (09/18/85)

> Here's a question for all the C language lawyers out there.  What should
> a C compiler make of the following:
> 
> 	static char *tgoto();
> 
> 	main()
> 	{
> 		.....
> 		if (tgoto(......).....
> 		.....
> 	}
> 
> In other words, we declare a function to be static, use it, but do not
> define it in the source file.  This occurs in libcurses/cr_tty.c (4.2BSD).
> The 4.2 compiler happily accepts this and links the 'static' tgoto to a
> definition in another source file.  In this case it is what the author
> intended, but it should really have been thrown out by the compiler,
> methinks.
> -- 
> Frank Cringle, Dept. of Computer Science, Univ. of Edinburgh
> UUCP:  <UK>!ukc!{hwcs,kcl-cs,ucl-cs,edcaad}!cstvax!fdc
> JANET: fdc@UK.AC.ed.cstvax  or   fdc@UK.AC.ed.ecsvax

From postnews Wed Sep 18 13:49:21 1985
> 
> 	static char *tgoto();
> 
> 	main()
> 	{
> 		.....
> 		if (tgoto(......).....
> 		.....
> 	}
> 
> In other words, we declare a function to be static, use it, but do not
> define it in the source file.  This occurs in libcurses/cr_tty.c (4.2BSD).
> The 4.2 compiler happily accepts this and links the 'static' tgoto to a
> definition in another source file.  In this case it is what the author
> intended, but it should really have been thrown out by the compiler,
> methinks.
> -- 
> Frank Cringle, Dept. of Computer Science, Univ. of Edinburgh
> UUCP:  <UK>!ukc!{hwcs,kcl-cs,ucl-cs,edcaad}!cstvax!fdc
> JANET: fdc@UK.AC.ed.cstvax  or   fdc@UK.AC.ed.ecsvax

Who knows. C knows that functions are extern (K&R says that somewhere)
so that a i
char f();

will be extern. Maybe it just ignores that static in some implementations
and believes it in others?

beal@polaris.UUCP (John L. Beal) (09/18/85)

> Every declaration which is outside the definition of any function
> declares an extern static something, even with "extern" or "static"
> or both omitted.
> 				Adam Reed
> 				ihnp4!npois!adam

Not true. Static is used to hide the declaration from other files
and the default of automatic to scope it throughout the program.