Actually C99 requires a declaration but not necessarily a prototype. A
prototype in C is a specific kind of declaration or definition, that
specifies the types (at least) of the parameters in the parentheses
indicating that it is a function, although many people misuse the term
to mean any declaration of a function, especially "published".
Perhaps I'm mixing up different meanings of "scope", but if I
understand
you correctly, then it is forbidden in C99 to do something like this
(IMHO bad style anyway):
foo.c
/* C99 would _require_ this; prior, we just get a warning. */
/* int foo(void); */
int main(void)
{
/* Wired, but C99 wouldn't complain, since prototype would be in
scope. */
/* int foo(void); */
return foo(); /* error: no prototype in scope */
}
<snip>
Sort of. Let's review:
int foo (void); is a prototype declaration of a function with no
arguments. int foo (); is a declaration but not a prototype.
Prototypes are better because they allow more error checking by the
compiler and appropriate automatic conversion of arguments (for
functions that take arguments, of course) but they are not required,
not even in C99. (They are, effectively, in C++.)
Before C99, you can declare a function at file scope a.k.a. top level
and it applies to the whole rest of the file (translation unit) unless
shadowed, or you can declare it within a function body or other block
and it applies only within that block. Or, if you call a named
function directly and it you haven't declared it either place, the
compiler assumes an implicit declaration like int foo() i.e. returning
int and accepting unspecified fixed default-promoted arguments.
It is considered poor style to put function declarations locally in a
function/block, because that's not where people expect to see them or
find them when looking, and it allows the coder to accidentally or
intentionally have inconsistent declarations e.g. char * foo (int) in
one place and void foo (int, char *) in another, which is wrong and
often badly wrong, without the compiler detecting. But it is legal.
C99 removes the last option, implicit declaration. You can declare,
prototype or not, at file scope or local scope. But you must declare.
- David.Thompson1 at worldnet.att.net