Error: initializer element is not computable at load time

后端 未结 2 2330
忘掉有多难
忘掉有多难 2020-12-10 13:52

I have a function that takes a struct, and I\'m trying to store its variables in array:

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


        
2条回答
  •  无人及你
    2020-12-10 14:20

    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;
    

提交回复
热议问题