declaration of functions

Karl Heuer karl at haddock.ima.isc.com
Tue Jun 13 06:13:49 AEST 1989


In article <14726 at duke.cs.duke.edu> apte at helios.UUCP (Jitendra Apte) writes:
>In article <4400001 at tdpvax> scott at tdpvax.UUCP writes:
>>	extern char *foo();
>>	char *foo();
>>They seem to be equivalent and I have found no mention in K&R.

They are equivalent.  And it makes no difference whether the function is
declared in a different file, or later in the same file%.

>[Quotes from K&R1]
>"At most one sc-specifier may be given in a declaration. If the sc-specifier
>is missing from a declaration, it is taken to be `auto' inside a function,
>`extern' outside. Exception : functions are never automatic".

Although this reaches the right conclusion in this case (since the declaration
is for a function), it should be noted that this clause is not quite correct
in general, since it would imply that "int x;" and "extern int x;" are also
equivalent.  Elsewhere in K&R1, it is stated that shared globals must be
declared with the "extern" keyword in N-1 files and without "extern" in
exactly one file.  This is one of the two contradictions in K&R1.$

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
________
% As long as it's global.  Forward declarations of static functions must use
  the keyword "static".
$ The other is that variadic functions are not permitted, yet printf() exists.
  (There is no mention of <varargs.h> in K&R1.)



More information about the Comp.lang.c mailing list