liveBook · Manning

Compound literal

A compound literal is a C expression consisting of a parenthesized type name followed by an initializer that creates an unnamed object.

How 2 Manning books explain it

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.

Read how Modern C explains compound literal →

Related concepts

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.