【发布时间】:2023-04-04 19:54:02
【问题描述】:
对不起这个问题的标题,我可能会在我得到答案后更新标题。
我有这个古老的代码编译和使用 gcc 4.x:
struct S {
int a;
int b;
};
int main(void)
{
return (struct S){1,2}.a;
}
如您所见,我将{1,2} 转换为struct S 以访问成员a。这个特性在 C 语言中是如何调用的?或者适用于这个构造的正确术语是什么?
任何 Visual Studio 版本都支持此功能吗?
【问题讨论】:
-
就像 GCC 6.25 Compound Literals
-
我发现了这个问题,请帮我关闭我的:stackoverflow.com/questions/3869963/compound-literals-in-msvc
-
@Patrick B:我的 MSVS 2012 Premium 副本不支持它。我得到
error C2059: syntax error: '{'。我了解 C99 将 在 MSVS2013 中得到支持。您可以免费下载并试用:MSVS 2013 Express Preview.
标签: c visual-studio struct