In article <cslopn$hs0$>, Chris Dollin <> writes:
> Grumble wrote:
>
> > I've come across some strange code. Here it is, stripped down:
> >
> > int main(void)
> > {
> > int *foo;
> > int *bar();
> > foo = bar(0);
> > return 0;
> > }
> >
> > If I understand correctly, line 2 in main() is a function prototype
> > which declares 'bar' as a function taking an unspecified number of
> > parameters, and returning a pointer to int?
> >
> > Can function prototypes really appear anywhere in the code?
>
> No. They are declarations, and declarations can't appear "anywhere".
> But they can appear at block start, even in C89.
Not if they're declarations of functions with static linkage. See
ISO 9899-1990 6.5.1:
The declaration of an identifier for a function that has block
scope shall have no explicit storage-class specifier other than
extern.
(This is part of the semantics of storage-class specifiers, not a
constraint, so it's not required to produce a diagnostic.)
This means that you cannot prototype a static function at block
scope.
I agree with Chris that even for functions with external linkage,
declarations at block scope are a poor idea; they accomplish little
(in practice, it's rarely useful to restrict the scope of a function
identifier), and since the same can't be done for static-linkage
functions, you'd end up with inconsistent placement of prototypes,
which can't help readability.
--
Michael Wojcik
Viewers are bugs for famous brands.
-- unknown subtitler, Jackie Chan's _Thunderbolt_