extern int f(); VS int f();
Karl Heuer
karl at haddock.ima.isc.com
Tue Feb 13 07:53:40 AEST 1990
Doug already posted the details, but it might not be clear what the answer is
to the original question.
In article <2912 at hcx1.SSD.CSD.HARRIS.COM> brad at SSD.CSD.HARRIS.COM (Brad Appleton) writes:
>Are the following function declarations equivalent?
>(1) extern int foo();
>(2) int foo();
Yes. They are completely identical in any sane compiler.
>I was just asked this question and I thought I knew a precise answer but
>I find that I am a little fuzzy on this one! I thought (2) is like a
>"forward" declaration in Pascal and that the only difference between these
>two is that If I use (2) then I may define the function "foo" (give it
>a body) later on in the same file. Is this right?
With either spelling, the actual definition for the function can appear in
either the same file or in a different file. (Some people prefer to use
"extern" for functions defined in separate files and omit "extern" for forward
declarations; this is a matter of taste.) But it must be a global function.
To forward-declare a static function%, you should use "static int foo();".
When dealing with objects rather than functions, the situation gets worse.
Karl W. Z. Heuer (karl at ima.ima.isc.com or harvard!ima!karl), The Walking Lint
________
% There may be some compilers that won't let you forward-declare a static
function. If you have to deal with such a beast, it's probably best to sort
the function definitions (if they aren't mutually recursive) or promote one
of them from static to global so you can forward-declare it.
More information about the Comp.std.c
mailing list