Hello all
I want to make my arrays of struct local. In a previous post (#56) I mentioned that I wanted to define some struct variables as static. Wildbull made the following reply. I do understand now, that the variables cannot be static in an array of struct.
wildbill:
Don't make any of your variables static. Static in this context in c++ means that all structs will share one copy of the static item. e.g. the led control structs will all share a single instance of pin.Clearly, this is not your intent. The pin can certainly be const (and probably should be) but static is not what you need and it's what the compiler is complaining about, however cryptically.
If the structs shall be declared locally what is the alternative to static which will keep the value for the next itineration?
How to I declare an array of struct if part of it is needed in setup() and the other part in loop()? Do I define the variables in global scope and initialize the variables locally
struct arrayOfStruct{
const int a;
int b;
float c;
const int d;
};
setup(){
arrayofStruct Struct[2] = {
{
.a = 1,
.b = 2
},
{
.a = 4,
.b = 5
}
};
}
loop(){
arrayofStruct Struct[2] = {
{
.c = 5,
.d = 7
},
{
.c = 7,
.d = 8
}
};
}
or do I declare part of the struct in setup() and part of it in loop()
setup(){
struct arrayOfStruct{
const int a;
int b;
};
arrayofStruct Struct[2] = {
{
.a = 1,
.b = 2
},
{
.a = 4,
.b = 5
}
};
}
loop(){
struct arrayOfStruct{
float c;
const int d;
};
arrayofStruct Struct[2] = {
{
.c = 5,
.d = 7},
{
.c = 7
.d = 8}
};
}
Or what is the way to do this?
Thank you...
moses