I have been programming C for more years than I care to admit and I cannot get this to work under Arduino. The structure works just fine and it compiles and runs. The problem is when I try to pass the structure to a routine I get the error below. It works in other environments.
any ideas?
Thanks
Mark
error: variable or field 'DrawOneBrick' declared void
typedef struct {
int top;
int left;
int bottom;
int right;
int lifeSpan;
Try it without the parnentheses around the type
void DrawOneBrick(TYPE_Brick *theBrick)
If that doesn't fix it, perhaps its also falling foul of the Arduino auto-prototyping . Put the function in a separate C file and see if it compiles ok.
If that doesn't fix it, perhaps its also falling foul of the Arduino auto-prototyping . Put the function in a separate C file and see if it compiles ok.
Indeed. Arduino's auto-prototyping is not very clever. It puts the prototypes directly after the include-statements, but before any type-definitions. So you need to declare the type in a separate h-file and #include it if you want to use it as a parameter in a function.
This won't work. When the arduino IDE generates the cpp-file from your project, it will put the prototype for do_something before the tydefef, and compilation will fail.
Thanks, skumlerud. Yet another reason to dislike the "magic" extra parser in the IDE, which gets a lot of declaration stuff wrong. If you change the argument to struct _foo_t* f, it works again.