-4

After upgrading from gcc 4.4.x to gcc 4.7.0, I started seeing:

error: initializer element not computable at load time

for the following snippet:

int prm_arr[] = {prm.field1, prm.field2, prm.field3};

This code worked fine with the gcc 4.4.x. I tried using -std=c99 option but it did not work. The following snippet might work

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

but, what is triggering this error?

hmofrad
  • 1,784
  • 2
  • 22
  • 28
bkhote
  • 1
  • 2
  • 2
    Please post a [MCVE](http://stackoverflow.com/help/mcve). In particular it matters whether this code is at file scope or block scope, and what `prm.field1` etc. are. – M.M Feb 18 '17 at 01:53

1 Answers1

0

In C89, initializer lists must be constant expressions known at compile-time. (however it works in C99 though). Hence what you are doing is not the correct way. The second snippet you posted is sure to work.

Jarvis
  • 8,494
  • 3
  • 27
  • 58
  • Initializers of non-static variables don't have to be constant expressions since C99, and OP says they tried `-std=c99` – M.M Feb 18 '17 at 02:29