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 construct typed unnamed objects in macro replacements and check macro argument compatibility.
- How deep it goes
- Defines the syntax and object semantics, then works through macro pitfalls, initialization checks, and contrasting local-object lifetimes.
- Examples
- Uses an array-of-names macro, a pointer-printing argument check, and while-versus-goto lifetime snippets.
- What you can do after
- Build it from scratch: write typed compound literals for macros and argument checks while avoiding invalid access after an object's lifetime.
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.
Related concepts
- objectproduces · A computational object is a runtime entity or structured value representing data, state, or a resource, with properties or operations defined by its programming model.
- 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 construct that expands or transforms source code, commands, or templates before or during execution.
- initializerhas part · An initializer is a function, declaration, or language construct that establishes the initial value or state of an object, value, computation, or process.
- constexprused by · constexpr is a C++ or C language specifier that allows entities or expressions to satisfy compile-time constant-evaluation requirements.
- effective typeconfigures · An effective type is the C type through which an object may be accessed under the language’s object-access rules.
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.

