gpt4 book ai didi

c - 错误 : initializer element is not computable at load time

转载 作者:太空狗 更新时间:2023-10-29 16:42:42 26 4
gpt4 key购买 nike

我有一个接受结构的函数,我试图将它的变量存储在数组中:

int detect_prm(Param prm) {
int prm_arr[] = {prm.field1, prm.field2, prm.field3};

return 0;
}

但是使用 gcc -Wall -ansi -pedantic-errors -Werror 我得到以下错误:

initializer element is not computable at load time

我觉得没问题,怎么了?

最佳答案

这在 C 中是非法的。初始化列表必须是常量编译时表达式。请改为执行以下操作:

int prm_arr[3];

prm_arr[0] = prm.field1;
prm_arr[1] = prm.field2;
prm_arr[2] = prm.field3;

关于c - 错误 : initializer element is not computable at load time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/160960/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com