小编cod*_*itz的帖子

初始化联合成员 - 使用 MS Visual Studio

需要在编译时初始化联合成员。阅读一些文章,似乎除了定义联合中的第一个条目之外别无他法。除非您使用 C99,否则您可以专门定义每个联合成员。

问题是我使用 Visual studio 2010 Prof。它似乎不支持 C99 或者我如何启用 ist?或者还有其他方法来初始化联合成员吗?

谢谢

typedef union {
int a;
char *atxt;
} MY_UNION_t;
typedef struct {
int foo;
MY_UNION_t un;
}GEN_DATA_t;

/* need to do following: */
GEN_DATA_t obj1 = {0,1}; /* Okay works */
GEN_DATA_t obj2 = {0,"bla"}; /* Does not work */

/* ISO C99 allows: */
GEN_DATA_t obj3 = {0,.atext="bla"}; /* However MS VS seem not to support this */
Run Code Online (Sandbox Code Playgroud)

c data-structures

4
推荐指数
1
解决办法
2460
查看次数

标签 统计

c ×1

data-structures ×1