Why static forward references

Doug Gwyn gwyn at brl-smoke.ARPA
Tue Jan 6 05:12:23 AEST 1987


In article <4870 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>In article <6927 at ki4pv.UUCP> tanner at ki4pv.UUCP (Tanner Andrews) writes:
>>extern char *blunge();			/* declare blunge */
>>char *gork() { return(blunge(69)); }	/* use blunge */
>>static char *blunge(arg) int	arg; { /* body of blunge here */ }

>But if the ANSI standard mandates that the code author must use
>`extern' or `static' on forward declarations, these compiler writers
>can save themselves the trouble of doing things right, or of fixing
>their linkers.  And that appears to be the entire motivation.

I don't think that is the issue at all.  The question is, WHICH
"blunge" should be used in the above example?  There might be
an external blunge() function also.  According to the "declare
things correctly before you use them" school, the external
blunge() should be used, not the internal one.  The one-pass
compilation model also requires this, since the meaning of the
reference to blunge() cannot depend on goings-on lexically later
in the source file.  This becomes even more significant when one
considers the fact that the rules for internal and external
symbol names (case folding, truncation, etc.) may well differ.

P.S.  "extern" is not required for such function declarations,
forward reference or no, since a function declaration with
neither "extern" nor "static" is taken to have external linkage if
linkage hasn't already been determined by a previous declaration.



More information about the Comp.lang.c mailing list