Hello.
I have N_SLAVES in my project and I want to store its configuration in a array of structures.
That configuration will not be variable in run time.
This is the code I'm trying:
#define N_SLAVES 1
typedef struct STATIONS {
int a;
int b;
float c;
};
const STATIONS station[N_SLAVES];
station[0] = (STATIONS) {1,2,3.1};
file.cpp:43:32: error: uninitialized const 'station'
file.cpp:44:1: error: 'station' does not name a type
Can you help me?
Thank you
sketch_jul29b:8: error: uninitialized const 'station'
sketch_jul29b:9: error: expected constructor, destructor, or type conversion before '=' token
Your code did not produce what you claimed it did.
I think the typedef is the issue. You need to declare it in a header file for it to work. Seemed to fix a similar issue I had in the past.
const STATIONS station[N_SLAVES];
station[0] = (STATIONS) {1,2,3.1};
You can't assign to a constant, and you can't assign like that anyway.
const size_t N_SLAVES = 3;
struct STATIONS
{
int a;
int b;
float c;
};
const STATIONS station[N_SLAVES] = {
{ 1, 2, 3.1f } // station[0]
, { 1, 2, 3.1f } // station[1]
, { 1, 2, 3.1f } // station[2]
};
int a = station[0].a;
int b = station[0].b;
float c = station[0].c;