Compound Literals

suggest change





C standard says in C11-§

A postfix expression that consists of a parenthesized type name followed by a brace enclosed list of initializers is a compound literal. It provides an unnamed object whose value is given by the initializer list.99)

and footnote 99 says:

Note that this differs from a cast expression. For example, a cast specifies a conversion to scalar types or void only, and the result of a cast expression is not an lvalue.

Note that:

String literals, and compound literals with const-qualified types, need not designate distinct objects.101)
This allows implementations to share storage for string literals and constant compound literals with the same or overlapping representations.

Example is given in standard:


Like string literals, const-qualified compound literals can be placed into read-only memory and can even be shared. For example,
(const char []){"abc"} == "abc"

might yield 1 if the literals’ storage is shared.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents