foo.c
#include "main.h"
unsigned char currentBar;
struct foo myFoo[getNumBars()];
void initMyFoo(void)
{
currentBar=(getNumBars()-1);
for(i=0; i<(sizeof(myFoo)/sizeof(myFoo[0])); i++)
{
myFoo[i].we = 1;
myFoo[i].want = 0;
myFoo[i].your = 0;
myFoo[i].soul = 0;
}
}
main.c
#include "foo.h"
unsigned char getNumBars()
{
return getDipSwitchValues();
}
initMyFoo();
(struct foo is declared in foo.h.)
This code should be executed without hard coding of the number for bars, since the number of bars will change depending on the user setting their DIP switches. Right now I cannot initialize myFoo; I get the error "constant expression expected in initializer". Should I initialize it like this:
struct foo myFoo[];
and change it later? If so, how do I make myFoo [] the correct length? I obviously don't have a constant that matches the size I want. Do I need to dynamically highlight this or something else?
, - ++ , ,