c/language/function declaration

A function declaration introduces an that designates a function and, optionally, specifies the types of the function parameters (the prototype). Function declarations (unlike ) may appear at block scope as well as file scope.

Syntax
In the of a function declaration, the  sequence, possibly modified by the declarator, designates the return type (which may be any type other than array or function type), and the  has one of three forms:

where

@1@ New-style (C89) function declaration. This declaration both introduces the function designator itself and also serves as a function prototype for any future, forcing conversions from argument expressions to the declared parameter types and compile-time checks for the number of arguments.

@2@ Old-style (K&R) function definition. This declaration does not introduce a prototype and any future will perform default argument promotions and will invoke undefined behavior if the number of arguments doesn't match the number of parameters.

@3@ ..

Explanation
The return type of the function, determined by the type specifier in and possibly modified by the  as usual in, must be a non-array object type or the type. If the function declaration is not a definition, the return type can be. The return type cannot be cvr-qualified: any qualified return type is adjusted to its unqualified version for the purpose of constructing the function type.

Function declarators can be combined with other declarators as long as they can share their type specifiers and qualifiers

If a function declaration appears outside of any function, the identifier it introduces has and, unless  is used or an earlier static declaration is visible. If the declaration occurs inside another function, the identifier has block scope (and also either internal or external linkage).

The parameters in a declaration do not need to be named:

Each parameter in a is a  that introduced a single variable, with the following additional properties:
 * the identifier in the declarator is optional


 * the only allowed for parameters is, and it is ignored in function declarations that are not definitions


 * any parameter of array type is adjusted to the corresponding pointer type


 * any parameter of function type is adjusted to the corresponding pointer type


 * the parameter list may terminate with, see  for details.


 * parameters cannot have type (but can have type pointer to void). The special parameter list that consists entirely of the keyword  is used to declare functions that take no parameters.


 * any identifier that appears in a parameter list that could be treated as a typedef name or as a parameter name is treated as a typedef name: is parsed as a new-style declarator for a function taking two unnamed parameters of type size_t and uintptr_t, not an old-style declarator that begins the definition of a function taking two parameters named "size_t" and "uintptr_t"
 * parameters may have incomplete type (except that in a, the parameter types after array-to-pointer and function-to-pointer adjustment must be complete)

See for other details on the mechanics of a function call and  for returning from functions.