相当于 Clang 中的 -fplan9-extensions 吗?
如何获得 -fplan9-extensions
在 GCC 中工作以在 Clang 中工作?
在使用指定的初始值设定项时,我在分配给匿名成员时遇到错误,而且我没有得到匿名成员类型的免费转换。这两个都可以在 GCC 下工作,并激活上述扩展。
typedef struct {int hi;} Embedded;
typedef struct {Embedded;} Encapsulating;
Encapsulating poo = {.hi = 3;};
error: field designator 'hi' does not refer to any field in type 'Encapsulating'
void takes_embedded(Embedded *m);
takes_embedded(&poo);
warning: incompatible pointer types passing 'Encapsuating *' to parameter of type 'Embedded *'
How do I get the anonymous struct/union behaviour activated by -fplan9-extensions
in GCC to work in Clang?
I'm getting errors assigning to members of anonymous when using designated initializers, and I'm not getting the free casting to the type of an anonymous member. Both these work under GCC with the aforementioned extension activated.
typedef struct {int hi;} Embedded;
typedef struct {Embedded;} Encapsulating;
Encapsulating poo = {.hi = 3;};
error: field designator 'hi' does not refer to any field in type 'Encapsulating'
void takes_embedded(Embedded *m);
takes_embedded(&poo);
warning: incompatible pointer types passing 'Encapsuating *' to parameter of type 'Embedded *'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是如何在 Clang 中获取
-fplan9-extensions
功能:一些
-fplan9-extensions
功能(struct { Embedded; }
部分)已在-fms-extensions
参数下可用,但是不支持为此类匿名成员指定初始值设定项。另一部分在本质上与 GCC 的 __attribute__((transparent_union)) 功能类似,Clang 已经支持该功能。Here's how to get the
-fplan9-extensions
functionality in Clang:Some of the
-fplan9-extensions
functionality (thestruct { Embedded; }
part) is already available under the-fms-extensions
argument, but designated initializers for such anonymous members are not supported. The other part is similar in spirit to GCC's__attribute__((transparent_union))
functionality, which Clang already supports.