C 为什么';没有类型转换的t复合文字赋值工作
我对C语言中的文字有一个问题C 为什么';没有类型转换的t复合文字赋值工作,c,c99,compound-literals,C,C99,Compound Literals,我对C语言中的文字有一个问题 int a; //a is an integer that is assigned an integer literal 414 a = 414; float b; //b is a float that is assigned a float literal of 3.14 b = 3.14; struct point { int x,y; }; struct point b; //{5,6} is a compound literal that i
int a;
//a is an integer that is assigned an integer literal 414
a = 414;
float b;
//b is a float that is assigned a float literal of 3.14
b = 3.14;
struct point {
int x,y;
};
struct point b;
//{5,6} is a compound literal that is assigned to a struture.
b = {5,6}; //doesn't work.
b = (struct point){5,6}; //works.
没有排字就不行了?原因是什么?(结构点){5,6}
作为一个整体是一个复合文字
C11§6.5.2.5复合文字
一种后缀表达式,由括号中的类型名和括号中的括号组成
初始值设定项列表是一个复合文本
既然在初始化之前可以从点b的偏差推断出类型,为什么它不起作用?@liv2hak
(struct point)
不是强制转换,它是复合文字的一部分。不能从符号表推断出来吗?@liv2hak:无法推断{5,6}
可以是int[2]
,也可以是结构{char a,b;}
。。。