Compound literal
A compound literal is a C expression consisting of a parenthesized type name followed by an initializer that creates an unnamed object.
Modern C, Third Edition
A compound literal is C syntax consisting of a type name in parentheses followed by an initializer that creates an unnamed object with the specified type and value.
- How it is used
- Uses compound literals to create unnamed objects in macros, check argument compatibility, and illustrate local object lifetime.
- How deep it goes
- Explains syntax, macro pitfalls, assignment checks, and lifetime differences between loop iterations and goto repetition.
- Examples
- Uses a bird-name array macro, a pointer compatibility check, and contrasting while and goto lifetime examples.
- What you can do after
- Apply compound literals in macros and type checks while avoiding invalid access after an object's lifetime ends.
Read how Modern C, Third Edition explains compound literal →
Modern C
A compound literal is a C expression consisting of a parenthesized type name followed by an initializer that defines an unnamed object.
- How it is used
- Deploys compound literals in typed macros, constant-like arrays, lifetime demonstrations, and compile-time argument checks.
- How deep it goes
- Defines syntax, object semantics, macro pitfalls, lifetime, repeated evaluation, and assignment compatibility without broader aggregate internals.
- Examples
- Uses a named corvid array macro, a `goto` lifetime experiment, and pointer-tracing macros for concrete demonstrations.
- What you can do after
- Apply compound literals in C macros and diagnose their constant-expression, lifetime, and type-checking consequences.
What to know first
- constantA constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention.
- integer constant expressionAn integer constant expression is an expression whose value can be determined during translation using only permitted constant operands and operations.
- macroA macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
- initializerAn initializer is a function, declaration, or language construct that establishes an initial value or state for an object, value, or computation.
Related concepts
- integer constant expressioncontrasts with · An integer constant expression is an expression whose value can be determined during translation using only permitted constant operands and operations.
- macrouses · A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
- objectproduces · An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
- initializerhas part · An initializer is a function, declaration, or language construct that establishes an initial value or state for an object, value, or computation.
- assignment compatibilityuses · Assignment compatibility is a type-system relation determining whether a value or expression of one type can be assigned to an object of another type.
- constexprused by · constexpr is a C++ or C language specifier that allows entities or expressions to satisfy compile-time constant-evaluation requirements.
Questions about compound literal
What is compound literal?
A compound literal is a C expression consisting of a parenthesized type name followed by an initializer that creates an unnamed object.
Which Manning books explain compound literal?
Modern C, Third Edition and Modern C.
What should I know before learning compound literal?
Manning books that teach compound literal usually introduce constant, integer constant expression, macro and initializer first.
What is the difference between compound literal and integer constant expression?
A compound literal is a C expression consisting of a parenthesized type name followed by an initializer that creates an unnamed object. An integer constant expression is an expression whose value can be determined during translation using only permitted constant operands and operations.
What are the parts of compound literal?
Compound literal includes initializer.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

