Question

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.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top