Why doesn't this work on the Arduino!?
typedef struct {
int a;
int b;
} TTallywag;
void DillyDally(TTallywag *tw){
// stuff...
}
In short, I don't actually know! But I know how to get around it!
To make it work, you have to change how you use your new data type - infact, your function parameters can't use types that you've
typedef'ed, but you can use the type if you do so thusly:
typedef struct _tallywag {
int a;
int b;
} TTallywag;
void DillyDally(struct _tallywag *tw){
// stuff...
}
According to the following page that I found, you
should be able to use the
TTallywag if you define it in a header file and including that into you sketch.
Note to self: Google 'Using headers in Arduino sketches'
I suppose technically defining types in header files is the right thing to do, but when you're dealing with a sketch that's only short, it seems such an overkill.
Now, the following
does works fine. You can use the types inside functions no problemo. Which is partly why I spent so much time tearing out my hair last night!
typedef struct _tallywag{
int a;
int b;
} TTallywag;
void *ShillyShally(int alpha, int beta){
static TTallywag tw;
// stuff...
tw.a = alpha;
tw.b = beta;
return &tw;
}
Must be some namespacing, or name mangling going on.
So it's not a huge problem, but if you're planning to share code modules between two devices, say one half in Linux written using GCC and the other half Arduino: Define your functions the latter way! That will work on both sides.