Declaration of an array of constants

Viewed 7366

I have that may be a problem of declaration :

I declare an array of const int :

const int my_array[] = {
    // data...
}

Then I need to declare another array of bytes of the form :

00 aa 01 bb 02 cc

where aabbcc is the 24-bits address in memory of the const int (I precise I code for a very particular platform, this explains that), so I wrote :

const char my_other_array[] = {
    00, (my_array >> 16) & 0xFF, 01, (my_array >> 8) & 0xFF, 02, my_array & 0xFF
}

but I get this error :

error: invalid operands to binary >>
error: initializer element is not constant

I thought about casting my_array :

const char my_other_array[] = {
    00, (((const u32) my_array) >> 16) & 0xFF, 01, (((const u32) my_array) >> 8) & 0xFF, 02, ((const u32) my_array) & 0xFF
}

but then I get a warning + error :

warning: initializer element is not computable at load time
error: initializer element is not computable at load time

What am I doing wrong ?

Here's the actual code, for those asking (I cut the irrelevant parts) :

#include <genesis.h>
#include "snake.h"

const u32 snake_patterns[] = {
    0x00024666,
    // ... some 100ths of lines
};

const u16 temp[] = {
    1, 0x9370, 0x9400, ((const u32) snake_patterns) & 0xFF, (((const u32) snake_patterns) >> 8) & 0xFF, (((const u32) snake_patterns) >> 16) & 0xFF
};

You'll notice things are a little more complicated, but I think the previous basic example (fixed with the appropriate brackets) shows the problem in a clearer way. Some may recognize a list of DMA calls for the Genesis VDP.

6 Answers
Related