0

I have matrix declaration implemented as follows:

int var_porcenComun;
int var_porceninv;

uint32_t pointers[] = {
    (uint32_t)&var_porcenComun, 9999999,
    (uint32_t)&var_porceninv, 999999
};

Those are all global variables. This code compiles fine.

Basically, the "pointers" holds the address of a variable and the maximum value it is supposed to hold.

My problem is that I have to add to this matrix a new variable, defined as uint64_t. Although the size of a pointer in my platform is 32 bits, I'd have to change the "pointers" to a uint64_t, because of the size of the variable. But when I do:

uint64_t pointers[] = {
    (uint64_t)&var_porcenComun, 9999999,
    (uint64_t)&var_porceninv, 999999
};

I get the following error:

: Error! E1054: Expression must be constant

Why is this error happening when I simply change the "pointers" type?

I'm using watcom 1.3 as compiler. Gcc and Visual Studio's have compiled fine this code.

Renan Greinert
  • 3,376
  • 3
  • 19
  • 29
  • Likely watcom would like this conversion to be done in runtime. This is really not portable, even if this platform happens to have 32 bit wide pointers, different compilers treat this code in a different way. We can try to find a way to fix this, but another compiler will have another problem with this, or the next version of GCC, or the next version of Visual Studio... – Gábor Buella Mar 24 '14 at 18:06
  • Is it global or local (and non-static) variables? Have you tried converting values twice (to uint32_t, then to uint64_t)? – keltar Mar 24 '14 at 18:10
  • Those are all global variables (I've just edited the question to add this info). I have tried converting twice, but I got the same error. – Renan Greinert Mar 24 '14 at 18:15

1 Answers1

2

Globals must be initialised with constant values. I guess watcom don't believe that your values are actually constants (maybe it is bad with compile-time calculations).

You can try to hack your compiler (like convert it to uint32_t, then automatic conversion may happen; or some bit tricks, none of which is guaranteed) or move array initialisaion out of static (e.g. moving it somehwere to init function that you call at the very beginning of main).

keltar
  • 17,711
  • 2
  • 37
  • 42