Skip to chapter content
navan✳THE BUILD LABC17 / GUIDE
0/24 read
APPENDIX A / C · REFERENCE NOTES

Appendix A · Reading declarations.

Decode types, qualifiers, arrays, pointers, functions, and linkage from the identifier outward.

BY NAVAN SAMILONG READC17 BASELINETHEORY FIRST
01 / THE MENTAL MODEL

The idea behind the syntax.

C declarations reuse expression-like syntax, which can make a dense type look mysterious. Begin at the identifier and follow the operators that bind to it. int *p declares p as a pointer to int. int values[4] declares values as an array of four int. int (*handler)(int) declares handler as a pointer to a function taking int and returning int; the parentheses are essential because a declaration without them would describe a different shape.

Qualifiers add another layer. const int *p allows p to point elsewhere but forbids modification of the pointed-to int through p. int *const p fixes the pointer value after initialization but allows modification of a compatible pointed-to int. Both can appear together. The qualifier describes an access path or object property at a particular part of the declaration; do not reduce every const to the same vague phrase.

02 / THE RULES

What C guarantees.

A typedef creates an alias for a type, not a new distinct type with automatic safety rules. It can make a callback signature or record interface easier to read, but too many aliases can hide ownership and mutability. Arrays and functions also change shape in parameter declarations: an array parameter is adjusted to a pointer, and a function parameter declaration is adjusted to a function pointer. This is why a parameter spelling alone does not carry an array length.

Storage-class specifiers and linkage determine where a name can refer to the same entity. extern commonly declares something defined elsewhere; static at file scope makes a name local to one translation unit. auto is rarely written for ordinary block-scope variables. A declaration can also be a definition, so a header's contents need care. The example places a function-pointer typedef beside an ordinary function and uses the alias as a parameter type.

03 / UNDER THE SURFACE

Why the detail matters.

When a declaration is hard to read, locate the identifier and first apply nearby brackets and parentheses before following pointer stars outward. Then attach the base type and qualifiers. For example, an array of function pointers and a pointer to an array of function pointers are different object shapes even though the words look similar. Drawing a small type tree is often faster than reciting a memorized phrase. A typedef can name the finished tree when it appears in several interfaces.

A declaration also tells only part of an API's story. int *p does not state whether p can be null, whether it points to one int or many, whether the callee may retain it, or who frees associated storage. Those facts live in a documented contract or in a higher-level wrapper. Qualifiers can enforce some access restrictions, and bounds can be passed as separate values, but the programmer still has to keep them consistent across calls.

04 / CODE, EXPLAINED

See the rule in context.

appendix-declarations.c
#include <stdio.h>

typedef int (*operation)(int);
int increment(int value) { return value + 1; }
int evaluate(int value, operation op) { return op(value); }
int main(void) {
    operation selected = increment;
    printf("%d\n", evaluate(9, selected));
    return 0;
}
FOLLOW THE EXECUTION

operation names a pointer-to-function type. selected receives the function designator increment, which converts to a compatible function pointer. evaluate receives that pointer and calls it with 9. increment returns 10, so the program prints 10. The alias improves readability but does not change the callback's parameter or return contract.

05 / THE BOUNDARY

Where the rule stops.

A typedef name can conceal a pointer. An API still needs to document whether that pointer may be null, how long its target lives, and who is responsible for any allocation.

06 / THE CONNECTION

Keep this model.

When decoding a declaration, separate four questions: what is the base type, what shape do pointer/array/function operators give the name, which qualifiers restrict access, and which scope or linkage rules make the name visible. That method is more reliable than memorizing one complicated example.

Finished reading?
Built with curiosity. By Navan Sami. ↗C · Types, memory, and the rules behind the code.