结构体系成员初始化的方法

blueboy82006 2012-08-05 06:35:39
请教一下,下面这是个什么语法?



struct abc_closure {
abc_handler p;
void *data;
intptr_t intdata;
int refcount;
};

struct abc_closure vac = { .p = &incoming_interest };



{ .p = &incoming_interest }
这个是在给p赋初值?
居然还有这种语法,第一次见。

求详细说明。
...全文
176 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
MC_LoveX 2012-08-06
  • 打赏
  • 举报
回复
对结构体中指定的成员进行初始化
V____ 2012-08-06
  • 打赏
  • 举报
回复
形式是这样的!

struct test{
int a;
};

struct test test={.a=123};
V____ 2012-08-06
  • 打赏
  • 举报
回复
这种写法不常用,直接初始化就好了

struct test{
int a = 0;
}test;

或者

memset(&test,0x00,sizeof(struct test));
省事
didijiji 2012-08-06
  • 打赏
  • 举报
回复
对指定成员初始化?
wshn13 2012-08-06
  • 打赏
  • 举报
回复
GCC已经支持C99了 VC6 可能不支持
txzsp 2012-08-06
  • 打赏
  • 举报
回复
什么C语言编译器?
自信男孩 2012-08-06
  • 打赏
  • 举报
回复
以前也见过这样初始化的。确实看着有点个性。
夏天__ 2012-08-06
  • 打赏
  • 举报
回复
定义结构体的时候,可以这样初始化。
blueboy82006 2012-08-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

C99标准的 指定初始化 语法
[/Quote]
多谢,有空查查
taodm 2012-08-05
  • 打赏
  • 举报
回复
C99标准的 指定初始化 语法
blueboy82006 2012-08-05
  • 打赏
  • 举报
回复
代码不是我写的,在一个开源模块中,可以编译通过。
DataChat.Club 2012-08-05
  • 打赏
  • 举报
回复
第一次见
南气子水 2012-08-05
  • 打赏
  • 举报
回复
我的编译器显示改代码的错误?
error C2146: syntax error : missing ';' before identifier 'p'
error C2501: 'abc_handler' : missing storage-class or type specifiers
error C2501: 'p' : missing storage-class or type specifiers
error C2146: syntax error : missing ';' before identifier 'intdata'
error C2501: 'intptr_t' : missing storage-class or type specifiers
error C2501: 'intdata' : missing storage-class or type specifiers
error C2059: syntax error : '.'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'

69,377

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧