I know I'm in a C++ compiler, but I typically create a typedef from structures, probably a holdover from earlier C programming. So this has my head spinning. I create a Typedef from a structure. After that, I have no trouble declaring a global or local version of that structure anywhere in a function, or outside of all functions (global). But when I try to create a function with this typedef as an arg, or even a function arg with a pointer the such a typedef, the compiler complains (and the complaint doesn't seem to make sense). Example...
typedef struct ss_tag {
uint16_t settingsSavedCount;
uint16_t codeID;
// a few more vars
uint8_t powerDownSaveFlag; // lets me know why we're being reset.
uint8_t future[10];
} Sunstates;
So now, this typedef seems as good as any other. Either of these statements compile fine...
Sunstates sunStates;
Sunstates * pSS = &sunStates;
But if I now try to create a function, with either an instance of this data type or a pointer to it, like so...
void systemDataVerify(Sunstates *pST) { }
The Arduino compiler offers this confusing error message...
Arduino: 1.8.3 (Windows XP), Board: "Arduino Nano, ATmega328"
SolarControler_21a:393: error: variable or field 'systemDataVerify' declared void
void systemDataVerify(Sunstates *pSS) { }
^
SolarControler_21a:393: error: 'Sunstates' was not declared in this scope
SolarControler_21a:393: error: 'pSS' was not declared in this scope
void systemDataVerify(Sunstates *pSS) { }
exit status 1 variable or field 'systemDataVerify' declared void
The fact that it doesn't like me declaring a function void is odd, but not as troubling as it calling my function a 'variable or field' and definitely not as strange as it saying my datatype (Sunstates) was NOT "declared in this scope." The data type was defined immediately before the function... and the fact I could declare both instances of the type AND pointers to it kind of proves it exists within the scope. Can someone help me understand why the compiler is complaining?
Edit... I was asked to include a short sketch that shows the problem...
uint8_t somefunction() {
return;
}
// define structure to hold/save setup and mode info
typedef struct ss_tag {
uint16_t settingsSavedCount;
uint8_t powerDownSaveFlag; // lets me know why we're being reset.
} Sunstates;
Sunstates sunStates; // create an instance
// create a function to accept a pointer to
// type Sunstates as an arg
void systemDataVerify(Sunstates *p) {
return;
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Now... I have discovered that if I remove the 'somefunction()' definition before the Structure definition, the problem goes away. And I'm using Arduino 1.8.3 to compile this.