CLA (C language) key terms
CLA (C language) · Get comfortable with the vocabulary.
- translation unit
- Related: preprocessor directive, object file
The complete source text a compiler processes after preprocessing: your .c file with all #include files and macro expansions inserted. Compilation and linkage operate on translation units, not on individual files.
- preprocessor directive
- Related: macro, include guard, translation unit
A line beginning with # that the preprocessor handles before compilation, such as #include, #define, #ifdef, and #pragma. Directives are not C statements and do not end with a semicolon.
- macro
- Related: preprocessor directive, include guard
A name replaced by text before compilation via #define. Object-like macros substitute a token sequence; function-like macros take arguments and should parenthesize them to avoid precedence surprises.
- include guard
- Related: header file, preprocessor directive
A pattern of #ifndef, #define, and #endif around a header's contents so repeated inclusion in one translation unit expands the body only once, preventing duplicate definitions.
- header file
- Related: include guard, declaration
A file conventionally ending in .h that declares functions, types, and macros shared across source files. It is inserted by #include; definitions of functions and objects normally belong in .c files.
- declaration
- Related: definition, function prototype
A statement that introduces a name and its type to the compiler without necessarily allocating storage, such as extern int count; or a function prototype. Declarations may repeat across translation units.
- definition
- Related: declaration, linkage
A declaration that also creates the entity: it allocates storage for an object or supplies a function body. Exactly one definition of an external object or function may exist across the whole program.
- linkage
- Related: definition, storage duration
The property determining whether a name can be shared across translation units. External linkage is visible program-wide, internal linkage (static at file scope) is limited to one translation unit, and no linkage applies to locals.
- storage duration
- Related: scope, static variable, dynamic allocation
How long an object's storage exists: automatic (block scope, ends at block exit), static (whole program run), or allocated (from malloc until free). Storage duration is distinct from scope.
- scope
- Related: storage duration, static variable
The region of program text where a declared name is visible: block scope, function prototype scope, file scope, or function scope (labels). Inner declarations can hide outer ones.
- static variable
- Related: storage duration, linkage, scope
A variable with static storage duration. At file scope, static gives internal linkage. Inside a function, static keeps one persistent copy initialized once, retaining its value between calls.
- integer promotion
- Related: implicit conversion, unsigned integer
The automatic conversion of types smaller than int, such as char and short, to int (or unsigned int) in most expressions. This affects arithmetic results and comparisons with unsigned values.
- implicit conversion
- Related: integer promotion, cast, unsigned integer
A conversion the compiler inserts without a cast, for example int to double in mixed arithmetic or a wider to narrower integer assignment. Narrowing conversions can silently lose data.
- cast
- Related: implicit conversion, void pointer
An explicit conversion written as (type)expression, requesting that a value be converted to the named type. Casts suppress warnings but do not make an unsafe conversion safe.
- unsigned integer
- Related: integer promotion, implicit conversion
An integer type storing only nonnegative values, with wraparound arithmetic modulo one more than its maximum. Mixing signed and unsigned operands in comparisons can convert the signed value unexpectedly.
- short-circuit evaluation
- Related: logical operator, sequence point
The rule that && stops evaluating once the left operand is false, and || stops once the left operand is true. The unevaluated right side's side effects never occur.
- sequence point
- Related: undefined behavior, short-circuit evaluation
A point in execution where all prior side effects are complete before later ones begin, such as the end of a full expression or a function call. Modifying one object twice between sequence points is undefined behavior.
- undefined behavior
- Related: sequence point, null pointer, buffer overflow
Program behavior the C standard imposes no requirements on, such as reading past an array bound or dereferencing a null pointer. The compiler may do anything, including appearing to work.
- function prototype
- Related: declaration, parameter, variadic function
A declaration giving a function's return type, name, and parameter types, ending in a semicolon. It lets the compiler check argument count and types at each call site.
- parameter
- Related: argument, array decay, function prototype
A variable declared in a function's parameter list that receives a copy of the corresponding argument's value on each call. Arrays as parameters decay to pointers.
- argument
- Related: parameter, pass by value
The expression supplied at a call site whose value is passed to the function's corresponding parameter. In C, arguments are passed by value unless a pointer is passed.
- pass by value
- Related: argument, pointer, parameter
C's only argument-passing mechanism: the function receives copies, so assigning to a parameter never changes the caller's variable. To modify a caller's object, pass its address.
- recursion
- Related: call stack, stack overflow
A function calling itself, directly or indirectly, with a base case that terminates the calls. Each active call consumes stack space, so deep recursion risks stack overflow.
- variadic function
- Related: function prototype, format specifier
A function accepting a variable number of arguments, declared with an ellipsis after at least one named parameter, such as printf. Arguments are read with va_start, va_arg, and va_end.
- array decay
- Related: pointer, parameter, sizeof operator
The automatic conversion of an array expression to a pointer to its first element in most contexts, losing size information. It is why sizeof on a parameter yields a pointer size, not an array size.
- pointer
- Related: dereference, pointer arithmetic, null pointer
An object holding the address of another object or function. Its type records the pointed-to type, which determines pointer arithmetic and dereferencing behavior.
- dereference
- Related: pointer, null pointer, undefined behavior
Accessing the object a pointer refers to using the unary * operator, as in *p. The pointer must hold a valid address of a live object of a compatible type.
- pointer arithmetic
- Related: pointer, array decay, one past the end
Adding or subtracting integers on a pointer moves it in units of the pointed-to type, not bytes. Valid results must stay within the same array or one past its last element.
- null pointer
- Related: dereference, undefined behavior, pointer
A pointer value guaranteed not to point to any object, written as NULL or a null pointer constant. Dereferencing it is undefined behavior, so check before use.
- void pointer
- Related: pointer, cast, dynamic allocation
A pointer to an unspecified type that can hold any object pointer without a cast. It cannot be dereferenced or used in arithmetic until converted to a concrete pointer type.
- one past the end
- Related: pointer arithmetic, array decay
The address immediately after an array's last element. Computing it is legal and supports loop termination tests, but dereferencing it is undefined behavior.
- dynamic allocation
- Related: heap, memory leak, dangling pointer
Obtaining memory at run time from the heap with malloc, calloc, or realloc, and releasing it with free. The programmer manages this lifetime; failing to free causes a leak.
- heap
- Related: dynamic allocation, memory leak
The region of memory from which malloc-family functions satisfy allocation requests. Its lifetime is controlled by explicit free calls rather than by block or program scope.
- memory leak
- Related: dynamic allocation, heap, dangling pointer
Heap memory that was allocated but is no longer reachable by any pointer and was never freed. The program's memory use grows until it exits or allocation fails.
- dangling pointer
- Related: dynamic allocation, undefined behavior, memory leak
A pointer that still holds the address of memory that has been freed or has gone out of scope. Using it is undefined behavior because the storage may already be reused.
- buffer overflow
- Related: undefined behavior, array decay
Writing past the bounds of an array or allocated block, corrupting adjacent memory. Functions like strcpy and gets cannot check destination size, so bounded alternatives are safer.
- structure
- Related: member access operator, typedef, structure padding
A user-defined type grouping named members of possibly different types into one object, declared with struct. Members are accessed with the dot operator, or arrow through a pointer.
- member access operator
- Related: structure, pointer
The dot (.) selects a member from a structure or union object; the arrow (->) selects a member through a pointer to one. The arrow is shorthand for (*p).member.
- structure padding
- Related: structure, sizeof operator
Unused bytes the compiler inserts between or after members so each aligns to its required boundary. It makes sizeof a struct exceed the sum of its members' sizes.
- typedef
- Related: structure, function pointer
A declaration creating an alternate name for an existing type, as in typedef struct Node Node;. It defines no new type and is often combined with structs and function pointers for readability.
- union
- Related: structure, structure padding
A type whose members share one storage area, so only one member's value is meaningful at a time. Its size is at least that of its largest member.
- function pointer
- Related: typedef, pointer, callback
A pointer storing a function's address, declared like int (*fp)(int). It enables callbacks and dispatch tables; calling through it invokes the pointed-to function.
- callback
- Related: function pointer
A function passed to another function, usually via a function pointer, so the callee can invoke it later. Common in sorting comparators and event handling.
- file stream
- Related: fopen mode, fclose, buffer flushing
An abstraction for reading or writing a file, represented by a FILE pointer returned from fopen. Standard streams stdin, stdout, and stderr are opened automatically.
- fopen mode
- Related: file stream, fclose
The string controlling how fopen opens a file: "r" read, "w" truncate and write, "a" append, with "+" for update and "b" for binary. Choosing the wrong mode silently destroys or fails to create data.
- fclose
- Related: file stream, buffer flushing
The function that flushes buffered output and releases a stream's resources. Failing to close files risks lost writes and exhausted file descriptors.
- buffer flushing
- Related: fclose, file stream
Forcing buffered output to be written to its destination, done by fflush or implicitly by fclose and normal program termination. Unflushed data can be lost on abnormal exit.
- format specifier
- Related: variadic function, undefined behavior
The conversion sequence in a printf or scanf format string, such as %d or %lf, telling the function how to interpret the corresponding argument. A mismatch causes undefined behavior.
- sizeof operator
- Related: array decay, structure padding, size_t
A compile-time operator yielding the size in bytes of a type or expression as type size_t. It does not evaluate its operand's side effects, except for variable-length arrays.
- size_t
- Related: sizeof operator, unsigned integer
The unsigned integer type used for object sizes and array indices, returned by sizeof and strlen. Printing it requires %zu; comparing it with a negative int can misbehave.
- call stack
- Related: recursion, stack overflow
The runtime structure holding one frame per active function call, with parameters, locals, and return address. Deep recursion or large local arrays can exhaust it.
- stack overflow
- Related: call stack, recursion
The failure that occurs when the call stack's fixed space is exhausted, typically by unbounded recursion or huge local arrays. The program usually terminates abnormally.
- object file
- Related: translation unit, linkage
The compiler's output for one translation unit, containing machine code plus symbol tables. The linker combines object files and libraries into an executable.
- logical operator
- Related: short-circuit evaluation, integer promotion
The operators &&, ||, and ! producing int values 0 or 1 from truth values. Unlike bitwise operators, && and || evaluate their operands as whole conditions with short-circuit behavior.