Chinaunix
标题:
为什么结构体中的成员变量可以用“点号”开头?
[打印本页]
作者:
abc78400123
时间:
2011-07-16 15:11
标题:
为什么结构体中的成员变量可以用“点号”开头?
static inline int ip_route_connect(struct rtable **rp, u32 dst,
u32 src, u32 tos, int oif, u8 protocol,
u16 sport, u16 dport, struct sock *sk)
{
struct flowi fl = { .oif = oif,
.nl_u = { .ip4_u = { .daddr = dst,
.saddr = src,
.tos = tos } },
.proto = protocol,
.uli_u = { .ports =
{ .sport = sport,
.dport = dport } } };
int err;
if (!dst || !src) {
err = __ip_route_output_key(rp, &fl);
if (err)
return err;
fl.fl4_dst = (*rp)->rt_dst;
fl.fl4_src = (*rp)->rt_src;
ip_rt_put(*rp);
*rp = NULL;
}
return ip_route_output_flow(rp, &fl, sk, 0);
}
这是tcp协议中的一个函数代码。
结构体中的成员变量为什么可以用点号开头呢?
如:
.proto = protocol,
作者:
myguyan
时间:
2011-07-16 15:16
声明一个结构的变量时,在结构体内,给这个变量的成员赋值。
忘了是gcc的扩展,还是c99的标准了
作者:
abc78400123
时间:
2011-07-16 15:30
回复
2#
myguyan
刚查了下C99的标准
谢谢了啊
初始化结构的时候现在可以这样写:
struct {int a[3], b;} hehe[] = { [0].a = {1}, [1].a = 2 };
struct {int a, b, c, d;} hehe = { .a = 1, .c = 3, 4, .b = 5} // 3,4 是对 .c,.d 赋值的
字符串里面,\u 支持 unicode 的字符
作者:
kangear
时间:
2012-10-31 09:30
哦……我明白 了
作者:
kangear
时间:
2013-11-04 20:46
还有我的影子。:)
作者:
GFree_Wind
时间:
2013-11-04 21:01
回复
3#
abc78400123
确定是C99标准吗?我怎么记得是GNU扩展呢?
作者:
zhangshuang2013
时间:
2013-11-09 11:37
这个是GUN标准,并不是c标准 ,加点表示结构体中可以不按成员顺序初始化。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2