Help with arrays.

Folks,

It has been a while and so the brain is a bit rusty.

Working on a slight improvement of my LED Clock, I was wanting to put a "leading" LED who's intensity grows as the second starts.

int HR_Size = 2;        //  1 before and 1 after
int MN_Size = 2;        //  1 either side
int SE_Size = 5;        //  All trailing and fading

//  Set up the colours for each hand.
//  HOUR HAND
int HR1_R = 0x55;    //Red  AM hours.
int HR1_G = 0;
int HR1_B = 0;

int HR2_R = 0x0D;    //Magenta  PM hours.
int HR2_G = 0;
int HR2_B = 0x0D;

int HH_R[HR_Size+1];

Originally I had the last line as:

int HH_R[3];

and realised that it had to (more correctly) the line in the first block.

But!

When I do that, it gives an error.

Ring_Clock9:120: error: array bound is not an integer constant

If I put it in brackets it does the same:

int HH_R[(HR_Size+1)];

Ok, what am I missing?

// change this
int HR_Size = 2;        //  1 before and 1 after

// to this
const int HR_Size = 2;        //  1 before and 1 after

int const HR_Size = 2; // 1 before and 1 aftercost

int HH_R[(HR_Size+1)];

If both variables and array are declared as global the compiler wants constant for array dimension. One would expect that.

If the dimension variable is used without "const" as local variable the compiler is happy, but you cannot initialize the (local) array. Than it will complain about variable size as you experienced. Kinda of late , but still an error.

Vaclav,

Thanks for that. It explains WHY it is happening.

I didn't understand the const part to be needed and how it played in the syntax.