【发布时间】:2020-04-30 03:51:35
【问题描述】:
我正在尝试使用指定的初始化器来初始化结构数组:
A[size].from = {[0 ... size - 1] = 0};
A[size].to = {[0 ... size - 1] = 0};
列表.h:
typedef struct Buffer
{
int from;
int to;
}buffer_t;
typedef struct shared_memory
{
buffer_t A;
int size;
} share_t
Main.c
#include <stdio.h>
#include "list.h"
buffer_t A[];
int size;
void main(int argc, char *argv[])
{
share->share_t *share = (share_t *)malloc(sizeof(share_t));
long arg = strtol(argv[1], NULL, 10);
size = arg;
share->A[size] = {[0 ... size-1] = 0};
}
但是,这是我收到的以下错误:
我正在使用 MinGW gcc 和命令提示符编译此代码,我正在 Visual Studio 中编写此代码。
【问题讨论】:
-
欢迎来到 SO。请发布更多显示
A、size等定义的代码。 -
我上传了更多代码,但在这样做时我发现了问题。 A[] 只能初始化一次。但是我可以在没有用户输入大小的情况下对其进行初始化。
-
编辑的代码包含很多错误,请发布您的实际代码并说明您尝试使用初始化程序实现的目标
-
buffer_t A[];不能没有大小,数组声明中必须知道大小 -
但大小必须由用户在命令提示符下输入。
标签: c arrays gcc struct designated-initializer