6.5.2.5/4
部分提供了关于 ( type-name ) { initializer-list } 形式的
。在这里:postfix-expression
的解释
If the type name specifies an array of unknown size, the size is determined by the initializer list as specified in 6.7.9, and the type of the compound literal is that of the completed array type. Otherwise (when the type name specifies an object type), the type of the compound literal is that specified by the type name. In either case, the result is an
lvalue
.
我不明白 the type of the compound literal
这句话。文字怎么可能有类型呢? 复合字面量的类型
是否表示对应未命名对象的类型?
例如
long long *longs = (long long []) {1333, 3123, 3, 122};
此处的initializer-list
用于初始化long long [4]
类型的无名对象。
也不清楚的目的是什么,在任何一种情况下,结果都是左值
。在 assignment-expression
中使用时,lvalue conversion
是在右操作数上执行的,因此它不再是左值。
最佳答案
据推测,“复合文字”是指使用“复合文字”语言构造指定的对象/值。值/对象在 C 中有类型。
使复合字面量成为左值的目的是这样的代码
int *x = &(int){42}; *x = 43;
有效。它使复合文字的行为有点像匿名变量。 (不过,不完全是。与常规变量不同,复合文字不能有存储类说明符,我个人认为这是语言缺陷。)
关于c - 后缀表达式 (type-name){initializer-list},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57459199/