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 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.

Read how Modern C explains compound literal →

What to know first

Related concepts

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.