I'm trying to use structs with Arduino but cannot pass a struct pointer with a function call. Everything works fine when adding a main function and compiling for my computer with gcc but with the Arduino IDE I get errors.
The code I tried was:
typedef union
{
struct
{
unsigned unit :2;
unsigned channel:2;
unsigned status :1;
unsigned group :1;
unsigned remote :26;
};
unsigned long data;
} Signal;
Signal signal;
void testPassingStruct(Signal *variable)
{
variable->status = 1;
}
void setup()
{
signal.status = 1;
testPassingStruct(&signal);
}
void loop()
{
}
And the errors was:
structtest:2: error: variable or field ‘testPassingStruct’ declared void
structtest:2: error: ‘Signal’ was not declared in this scope
structtest:2: error: ‘variable’ was not declared in this scope
You have several unnamed items. This happens with
typedef
s. You could try,Then in your code you need,
You can also use defines for masks and bit fields. Often it makes control of what bit is where clearer and the compiler will generate similar code in both cases. For instance,
Especially with system programming where the bits matter, this is better as I don't believe that the 'C' bit fields specify how they are placed. Most of all, I am sure it will compile.
It is basically the union and the lack of a the name for the structure member (I've called it parts in the code below). Try this