[comp.lang.c] Function declarations in the dpANS

chris@mimsy.UUCP (Chris Torek) (09/13/88)

>>In article <1275@mcgill-vision.UUCP> mouse@mcgill-vision.UUCP
(der Mouse) writes:
>>> I *would* be surprised to find that [this doesn't work]
>>> foo() { ... { double glurf(char*,int); ... } }
>>> static double glurf(char *s,int maxlen) { ... }

>In article <13344@mimsy.UUCP> I answer:
>>Surprise!

In article <1309@mcgill-vision.UUCP> der Mouse replies:
>You have such a lovely way of phrasing things, Chris... :-)

Thank you.

[me:]
>>Putting these together, the *only* legal ways to write this are:
>>	static double glurf(char *, int);
>>	foo() { ... /* call glurf */ ... }
>>	static double glurf(char *s, int maxlen) { ... }
>>or
>>	static double glurf(char *s, int maxlen) { ... }
>>	foo() { ... /* call glurf */ ... }

[der Mouse:]
>Since the whole idea was to document the fact that foo calls glurf,
>near the point of call (ie, in foo), how about:
>
>[1]	static double glurf(char *, int);
>[2]	foo() { double glurf(char *, int); ... /* call glurf */ ... }
>[3]	static double glurf(char *s, int maxlen) { ... }
>
>Is this permitted?

\S3.1.2.2, Linkages of identifiers, says:

    There are three kinds of linkage: external, internal, and none. ...
    If the declaration of an identifier for ... a function has file
    scope and contains the storage-class specifier |static|, the
    identifier has internal linkage.

(Hence we conclude that `glurf' in line [1] above has internal linkage.) 

    If the declaration of an identifier for a function has no storage-
    class specifier [line [2] above], its linkage is determined exactly
    as if it were declared with the storage-class specifier |extern|.

(so we back up one paragraph, which says:)

    ... the identifier has the same linkage as any visible declaration
    of the identifier with file scope.  If there is no visible declaration
    with file scope, the identfier has external linkage.

(which tells us that since it has file scope and internal linkage, the
declaration on line [2] above also has internal linkage.)

Since the scopes and linkages agree, the answer appears to be that
this format is permitted.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris