错误:初始元素不是在加载时间可计算 [英] Error: initializer element is not computable at load time

查看:1668
本文介绍了错误:初始元素不是在加载时间可计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在,需要一个结构的函数,我试图存储在数组中的变量,但我得到这个,当我运行gcc -Wall -ansi -pedantic-错误-Werror

I have in a function that takes a struct, and I'm trying to store its variables in an array, but I get this when I run gcc -Wall -ansi -pedantic-errors -Werror

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

  return 0;
}

我得到的错误:初始元素不是在加载时间可计算的,当我尝试编译上面。这看起来好像没什么问题,什么是错?

I get Error: initializer element is not computable at load time when I try to compile the above. It looks fine to me, whats wrong?

推荐答案

这是在C初始化列表违法必须是恒定的编译时间前pressions。执行以下操作来代替:

This is illegal in C. Initializer lists must be constant compile time expressions. Do the following instead:

int prm_arr[3];

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

这篇关于错误:初始元素不是在加载时间可计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆