I’m attempting to use a struct for an Arduino project. When I attempt to use objects defined by the struct, Visual Studio Intellisense is unhappy and flags them as unknown. Enclosed pix shows the error.
From all I can find on the net this APPEARS to be the right way to use them - where am I stepping on my weenie?
struct Menu {
char name[16];
byte order;
byte state; // System State assgined to this menu is selected with RE switch
int display; // where 7-seg data for this menu item is held
byte ledpin;
};
Menu Count_menu;
Menu Angle_menu;
Menu Speed_menu;
Menu Clear_menu;
Menu Step_menu;
/* the lines below are flagged as 'no storage class or type identifier' */
Count_menu.state = STATE_DATA;
Count_menu.ledpin = MLED_COUNT;
Angle_menu.state = STATE_DATA;
Hmm - good idea but no go. When I use the struct in front of the declarations, it gets unhappy with the '.'.
From what I've read, Arduino is c++ and Intellisense only gets bummed when I try to USE the items defined with the struct.
My basic layout SHOULD be ok... i.e. not having to prefix the declarations.
Actually that WAS all the code - it was just a little test bit I was doing.
I've since found out that there are some... issues using a STRUCT in Arduino C++ - So I've abandoned that idea and just created an ADC and it works nearly the same and perhaps better.
I get the impression that STRUCT was a form from 'plain' C that didn't carry over so well to C++ - and doing a class is nearly as easy.
My approach is to typedef the struct all in one go:
typedef struct {
int a;
int b;
} MyType;
MyType nerdy_redhead;
The label you use after the keyword "struct" is the struct's name, which can be omitted. The label after the struct definition is the typedef'd alias, which can also be omitted. You get your pick which to use. My way is all I want 99.999% of the time, so I don't bother with the struct label. If it makes you feel better, you can still include it though:
Thanks to all who replied. YES - the DEFINES were not included in my sample... They are correct and where not creating the problem I was having. As I said - it appears that STRUCT's don't seem to work in Arduino C. They define correctly, but when I attempt ANY form of assignment, it fails. I read something about 'namespace' issues - it got sorta nasty.
In any case, creating and ADC for this is a better solution (maybe a tad more work) but works nicely in the end.
Further comments on this: I'm working in Visual Studio 2012 with the Visual Micro plug-in. In the included screen shot you can see how VS is complaining about the definition. No amount of 'typedef' or 'struct' positioning would make it happy... so I gave up on STRUCT. I do like the ADC's as a better solution anyway...
As I said - it appears that STRUCT's don't seem to work in Arduino C.
You appear to be the only one having problems with them, and you posted code that doesn't compile, to "illustrate" the vaguely worded problem description. No one else can replicate your problem or see what the real errors, not your handwaving, are.
Apologies to All! Something is def broke in my kludge program as I just made a tiny 'test-struct' program and it behaves as expected. My dad always said there was no point in being stupid unless you could show it...
Actually that WAS all the code - it was just a little test bit I was doing.
…
the full code is in 5 files and would be a PITA for me to load and you to read.
How Can I store the whole mystruct table in the EEPROM. Please help.