我有以下代码:
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给我报错:
错误: 在左大括号标记之前缺少表达式 test->mem = {1,2,3,4,5,6}; 左箭头指向左括号。
这是什么问题呢?
谢谢!
编辑: 我也尝试了这段代码:
long mem[1000] = {1,2,3,4,5,6};
test->mem = mem;
我从gcc得到这个错误:
error: 将'type 'long int *'的值赋给类型为'long int[1048576]'的变量'test->mem'时出现不兼容的类型 test->mem = mem;
我不能使用任何C函数。