在C99中,您可以通过这种方式简单地初始化静态分配的结构
struct sometype {
int a;
double b;
};
sometype a = {
.a = 0;
};
Run Code Online (Sandbox Code Playgroud)
好吧,这不适用于像这样的堆上的结构.
struct sometype *a = malloc(sizeof(struct sometype));
*a = {
.a = 0;
};
Run Code Online (Sandbox Code Playgroud)
使用GCC 4.9.2,编译器抱怨
error: expected expression before '{' token
Run Code Online (Sandbox Code Playgroud)
我知道这很愚蠢,但是有什么语法或技术原因我不能这样做吗?