Functions and Modules in C
Declaring, defining and organising functions across files — prototypes, headers, linkage and storage. Call by value/reference and storage classes have their own pages earlier in this subject.
This is an overview — pick a sub-topic below.
Sub-topics (14)
Function Declarations and Prototypes
A prototype tells the compiler a function's name, return type and parameter types before it is used.
Function Definitions
The function's body — where the work happens.
Arguments and Parameters
Parameters are the variables in the definition; arguments are the values passed in a call.
Pass by Value
C always copies argument values into parameters.
Recursion in C
A function calling itself, with a base case to stop.
Variadic Functions
Functions taking a variable number of arguments, like `printf`, using `stdarg.h`.
Inline Functions
`inline` suggests replacing calls with the function body; `static inline` in headers is the common safe pattern.
Header Files
`.h` files share declarations (prototypes, types, macros, `extern` variables) between source files.
Include Guards
Prevent a header's contents from being processed twice.
Separate Compilation
Each `.c` file compiles to an object file; the linker combines them.
Linkage
Whether a name refers to the same entity across files: external, internal or none.
Storage Duration
How long an object lives: automatic (block), static (whole program), allocated (malloc/free) or thread (`_Thread_local`).
Scope
Where a name is visible: block, file, function (labels) or prototype scope.
External and Static Linkage
`extern` declares something defined in another file; `static` hides a file-level name from other files.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.