Skip to main content
A function declaration introduces a function’s identifier and return type to the compiler. If the declaration explicitly specifies the types of its parameters, it serves as a function prototype. A prototype establishes the complete function signature, enabling the compiler to perform strict type-checking on arguments. A declaration without parameter types does not act as a prototype and bypasses strict argument type-checking.

Anatomical Components

  • return_type: Specifies the exact data type of the value the function yields to the caller. If the function does not return a value, the void keyword must be used.
  • function_name: The unique identifier for the function, adhering to standard C identifier rules.
  • Parameter List: A comma-separated sequence of data types representing the inputs. Parameter identifiers (names) are optional in the declaration, as the compiler only requires the types for signature matching.
  • Terminator: A declaration must be terminated with a semicolon (;), distinguishing it syntactically from a function definition.

Syntax Variations and Rules

Omission of Parameter Names Because the compiler only needs type information to validate calls against a prototype, parameter names can be omitted entirely.
Non-Prototypes vs. Strict Zero-Parameter Declarations In C (prior to C23), an empty set of parentheses () denotes an unspecified number of arguments. This forms a declaration but not a prototype. To explicitly declare a function prototype that accepts strictly zero arguments, the void keyword must be placed inside the parentheses.
Variadic Functions A prototype can specify that a function accepts a variable number of arguments using an ellipsis (...). The ellipsis must be the final parameter, and it must be preceded by at least one named parameter.

Storage Class and Function Specifiers

Function declarations interact with the linker and compiler behavior through specific keywords, divided into storage class specifiers and function specifiers. Storage Class Specifiers
  • extern (Default): Function declarations possess external linkage by default. The extern keyword is implicit, meaning the function can be defined in a different translation unit.
  • static: Restricts the function’s visibility (internal linkage) strictly to the translation unit in which it is declared.
Function Specifiers
  • inline: Instructs the compiler to attempt inline expansion of the function to eliminate function-call overhead.
  • _Noreturn (C11): Indicates to the compiler that the function will not return to its caller (e.g., a function that terminates the program).

Array and Pointer Parameter Equivalence

In the context of a function declaration, array parameters are automatically adjusted to pointers of the corresponding type. The following declarations are semantically identical to the compiler:
Tired of Poor C Skills? Fix That With Deep Grasping!Learn More