【发布时间】:2014-02-13 03:13:32
【问题描述】:
我有以下代码:
typedef struct Test {
long mem[1000];
} Test;
extern Test *test;
int main() {
Test *test = (Test *)malloc(sizeof(Test));
test->mem[0] = 1;
test->mem[1] = 2;
test->mem[2] = 3;
test->mem[3] = 4;
test->mem[4] = 5;
test->mem[5] = 6;
return 0;
}
它工作正常,但我想将 mem 数组的初始化更改为这种方式:
test->mem = {1,2,3,4,5,6};
但是 gcc 给了我这个错误:
error: '{' token test->mem = {1,2,3,4,5,6} 之前的预期表达式; 箭头指向左开括号。
它可能是什么?
谢谢!
编辑: 我也试试这段代码:
long mem[1000] = {1,2,3,4,5,6};
test->mem = mem;
我从 gcc 收到此错误:
错误:分配给类型“long int[1048576]”时的类型不兼容 从 type 'long int *' test->mem = mem;
我不允许使用任何 C 函数。
【问题讨论】: