c/language/function definition

A function definition associates the function body (a sequence of declarations and statements) with the function name and parameter list. Unlike, function definitions are allowed at file scope only (there are no nested functions).

C supports two different forms of function definitions:

where

@1@ New-style (C89) function definition. This definition both introduces the function itself and serves as a function prototype for any future, forcing conversions from argument expressions to the declared parameter types.

@2@ Old-style (K&R) function definition. This definition does not behave as a prototype and any future will perform default argument promotions.

Explanation
As with s, the return type of the function, determined by the type specifier in and possibly modified by the  as usual in, must be a complete non-array object type or the type. If the return type would be cvr-qualified, it is adjusted to its unqualified version for the purpose of constructing the function type.

As with s, the types of the parameters are adjusted from functions to pointers and from arrays to pointers for the purpose of constructing the function type and the top-level cvr-qualifiers of all parameter types are ignored for the purpose of determining compatible function type.

Within the function body, every named parameter is an expression, they have automatic  and. The layout of the parameters in memory (or if they are stored in memory at all) is unspecified: it is a part of the calling convention.

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

{{rrev|since=c99|

__func__
Within every, the special predefined variable with block scope and static storage duration is available,  as if defined immediately after the opening brace by

This special identifier is sometimes used in combination with the predefined macro constants and, for example, by assert. }}