Reading keywords by the job they do
Connect types, declarations, control flow, type queries, generic selection, and function specifiers.
In this chapter10 sections
A keyword becomes easier to remember when you know its job. We will group keywords by the work they express, then connect each group to an idea you already know. The index in the next chapter gives the complete version-labelled list.
1. Describe a type, or give a type another name
char, short, int, long, signed, and unsigned form supported integer-type combinations. They do not choose one universal byte width. float, double, and long double describe floating types, not exact decimal arithmetic by default. _Bool is the C17 Boolean type; void covers no value and the generic object-pointer form void *.
struct introduces structure types with ordered members; union introduces union types with shared storage; enum introduces enumerated types and constants. ISO C calls arrays and structures aggregates; a union is a separate type category. typedef supplies an alias for a type rather than a distinct new type.
typedef unsigned Count;
unsigned original = 2;
Count *same_type = &original;
*same_type = 3;
The alias Count is compatible with unsigned because it names the same type. It does not enforce a special “count only” domain. For stronger interfaces, use a deliberate representation and validation policy, as explained in types and data interfaces.
2. Refine a declaration’s access and lifetime rules
const, volatile, restrict, and the qualifier use of _Atomic answer different access questions. _Atomic(type-name) is also an atomic type-specifier form. None of these is a universal “safer code” switch. Use the qualifiers chapter for the contracts.
auto, register, static, extern, _Thread_local, and typedef are the C17 storage-class-specifier spellings. Their grammatical category does not mean each allocates storage. Static has different block, file, and array-parameter roles; extern can inherit prior linkage. Read storage classes in context.
3. Choose paths, repeat work, and transfer control
if/else branch on a scalar condition. switch selects using an integer controlling expression; case and default introduce labels within its rules. Switch does not automatically stop after a matching case: control can fall through unless another transfer prevents it.
for, while, and do organize repetition. For is not limited to a preknown number of iterations; it places initialization, a condition, and an update in one construct. While tests before the body; do tests after the body if control reaches that test.
int step = 0;
int total = 0;
for (; step < 5; ++step) {
if (step == 2) continue;
total += step;
}
The sum is 8: 0 + 1 + 3 + 4. Continue at step 2 still reaches the for update, so the loop progresses. break exits the nearest enclosing loop or switch. continue targets the nearest enclosing loop's continuation point. return exits the current function, optionally supplying a value under its return-type rules.
goto jumps to a label within the same function, subject to constraints such as entry into variably modified scopes. It can make control flow hard to follow; a bounded forward cleanup path can also make ownership clearer. Judge the actual flow, not a slogan. The cleanup chapter shows that use.
4. Query a type or assert a translation-time contract
sizeof queries size in C bytes; _Alignof queries type alignment. _Alignas requests an allowed alignment for a declaration, subject to its restrictions; it is not a request for a particular byte size. _Static_assert checks its required constant condition during translation.
Generic selection uses _Generic to choose one association based on the controlling expression's type. The controlling expression is not evaluated. In C17 its type is determined with the specified as-if conversions; this is not a tool for preserving every top-level qualifier.
int value = 3;
int result = _Generic(value++, int: 7, default: 9);
result is 7 and value remains 3. The selected result expression can itself have runtime work. Unselected associations still must meet syntax and constraint requirements, so _Generic cannot hide a type-invalid expression in another arm. Read constant expressions for the different translation-time categories.
5. Optional: function specifiers are promises with rules
inline and _Noreturn after the function introduction
inline is a function specifier with definition and linkage rules. It does not guarantee that a call is replaced by the function body, and a compiler may expand a call without inline. A common simple header idiom uses static inline, giving a separate internal-linkage function in each translation unit that includes the definition.
#include <assert.h>
static inline int larger(int left, int right)
{
return left > right ? left : right;
}
int main(void)
{
assert(larger(3, 8) == 8);
assert(larger(5, 5) == 5);
return 0;
}
This example is one translation unit. External-linkage inline definitions need additional C-specific rules about providing an external definition; do not copy C++ inline assumptions into a C header. Expansion, function identity, and linking are separate issues.
_Noreturn declares that a function does not return to its caller. It is a contract, not an optimization that makes returning safe. C23 deprecates this spelling in favor of the [[noreturn]] attribute; noreturn there is an attribute name, not another language keyword.
6. Version changes add spellings and change roles
C23 makes bool, true, false, alignas, alignof, static_assert, and thread_local language spellings without relying on their older header-macro routes. nullptr is a predefined null-pointer constant with its own type; it is not the character '\0' or an ordinary object named NULL.
C23 adds constexpr, type-inference uses of auto, typeof, typeof_unqual, _BitInt, and conditionally supported decimal floating types. Typeof_unqual removes top-level and atomic qualification, not pointed-to const: typeof_unqual(const int *const) still denotes a pointer to const int.
_Complex and _Imaginary spell reserved type facilities whose applicable support rules must be checked; a keyword's reservation is not proof of every optional feature. Use the complete keyword index for versions and follow-up chapters.
7. Thought check: is a keyword’s meaning fixed by one slogan?
Does every use of static mean “this local survives between calls”?
No. That describes one block-scope object case. File-scope static establishes internal linkage; an array-parameter static states a minimum access contract. First identify the declaration context, then apply its rule.
Sources and further reading
Primary references: WG14 N1570 6.2.5, 6.5.1.1, 6.5.3.4, 6.7.1–6.7.5, 6.7.8, and 6.8; WG14 N3096 (C23 notes). These are public committee drafts; the examples here use a C17 baseline. WG14 DR481 records the C17 generic-selection controlling-type correction; N1570 alone predates that correction. GCC inline documentation distinguishes its language modes.
Before you move on
- Keywords become easier to interpret when grouped by their jobs.
- A spelling can participate in declarations, control flow, or special expression rules depending on its role.
- New spellings and semantic changes must be associated with the selected C edition.
Keep these ideas separate
- Same spelling / Same rule
- A familiar spelling can have version-specific meaning; C and C++ can also give it different rules.
Choose one keyword and explain its job using a rule and a small example rather than a memorised label.
Optional: say it aloud or keep a note. You can continue whenever you are ready.Check your understanding
Optional. Answers are not saved or sent, and reading stays unrestricted.
Read the explanation for every choice
- Always terminate the entire program immediately.
Returning from an ordinary called function normally resumes its caller.
- Repeat the function body.
return ends the current invocation rather than starting another iteration.
- Finish the current function invocation, supplying a value when required.
✓ Correct reasoning. The function’s return type and return statement determine the value rules.
C17
Quick reference from the earlier edition
Retained for existing section links and saved passages. Exact corrections are recorded in the source review.
Each keyword in C has a specific role and semantics within the language. The following paragraphs elaborate on the most significant keywords and their usage, referencing code examples where appropriate.
Data Type Keywords
-
int, char, float, double, short, long, signed, unsigned: These keywords specify arithmetic types or type combinations. ISO C sets minimum requirements; exact sizes and ranges depend on the implementation. For example,
intis an integer type, whileunsigned longis an unsigned integer type with an implementation-defined range meeting the standard’s minimum requirements. The choice of type affects memory usage, range, and arithmetic behavior. -
void: Indicates the absence of a value, for example a function with no return value.
void *is a generic object-pointer type; a non-nullvoid *can still point to a real, typed object.
Control Flow Keywords
-
if, else, switch, case, default: These keywords implement conditional branching.
ifandelseallow for two-way branching, whileswitch,case, anddefaultenable multi-way branching based on the value of an expression. -
for, while, do: These keywords define loops.
foris used for counted loops,whilefor condition-controlled loops, anddofor loops that execute at least once. -
break, continue:
breakexits the nearest enclosing loop or switch, whilecontinuetransfers to the loop’s continuation point; aforloop still evaluates its update expression before testing the condition again. -
goto: Provides an unconditional jump to a labeled statement. Its use is generally discouraged due to the risk of unstructured code.
Storage Class Specifiers
-
auto: In C17, an automatic-storage specifier, normally omitted for ordinary local objects. C23 additionally permits type inference in declarations such as
auto n = 10;; that form is not valid C17. -
register: Suggests fast access, without guaranteeing CPU-register placement or speed. The implementation may ignore the suggestion, but C17 and C23 still prohibit direct unary
&on a register-declared object. -
static: In ordinary object declarations without thread-local storage, selects static storage duration; at file scope, establishes internal linkage for object or function identifiers. Scope separately controls name visibility. Static also has a distinct minimum-bound role in array parameters.
-
extern: Commonly declares an object or function with linkage so declarations in different translation units can refer to the same entity. It does not mean “always defined elsewhere”:
extern int x = 1;at file scope is a definition. A header usually usesextern int x;, with one definition in a source file.
Type Qualifiers
-
const: Prevents modification through a const-qualified lvalue. An object originally defined as const must not be modified even after casting away const; that is undefined behavior. A mutable object viewed through a pointer-to-const can still be changed through another valid, non-const access path.
constalone does not make an ordinary C17 integer object an integer constant expression. -
volatile: Gives accesses special observable semantics, useful for implementation-defined hardware access and certain signal-handler objects. It does not provide atomic operations, memory ordering between threads, or protection against data races. Use atomics or appropriate synchronization for shared mutable thread data.
-
restrict: A C99 pointer-access contract that can enable optimization. It restricts how relevant modified objects are accessed during an associated execution; it does not simply forbid every other pointer or all read-only aliasing. Section 15 expands the rule.
Function-Related Keywords
-
return: Exits a function and optionally returns a value to the caller.
-
inline: A C99 function specifier with definition and linkage rules. Call substitution is an implementation choice, not a guarantee; a compiler may also expand calls without inline.
-
_Noreturn: Specifies that a function does not return to the caller (C11).
Other Keywords
-
struct, union, enum, typedef:
struct,union, andenumintroduce structure, union, and enumerated types, respectively. ISO C’s aggregate category includes arrays and structures, not unions.typedefgives an existing type another name; it does not create a distinct type. -
sizeof: Produces the size of a type or expression in C bytes, with result type
size_t. Its operand is usually not evaluated; variable-length-array types introduce exceptions. -
_Alignas, _Alignof: Control and query memory alignment (C11).
-
_Atomic: Specifies atomic types and supported atomic operations (C11); overall thread safety still requires correct synchronization, lifetimes, and algorithm design.
-
_Thread_local: Declares thread-local storage (C11).
-
_Bool, _Complex, _Imaginary: Boolean, complex, and reserved imaginary-type support. Imaginary types are optional, and C11/C17 implementations may also omit complex types. In C23,
boolis the preferred spelling of_Bool. -
_Static_assert: Compile-time assertion (C11).
-
_Generic: Enables generic programming by selecting expressions based on type (C11).
Each keyword is reserved and cannot be used as an identifier (variable or function name) in user code.
Ready for the next idea?
Mark this chapter as read whenever you feel ready.