I'm unsure how this will be handled by the Arduino compiler. If anyone can explain what and why, I'd appreciate it. This is obviously very simplified, but it does contain the actual issue.
At the module level I have this union
. I understand that this is strictly speaking not correct C++, but it does work for me, at least when used directly and not passed as a argument to a function.
union _TAT { // access as bytes or uint32
uint32_t wide = 0;
uint8_t bytes[4];
};
_TAT oneTAT; // a variable of _TAT
Suppose I also have a function that works on these:
void fix_Term(_TAT atat) {
atat.wide = 0;
atat.bytes[3] = 17;
}
...and I invoke it with:
fix_Term(oneTAT);
As I understand it, passing AnArray[]
is equivalent to passing *AnArray
, so the function might/should see atat.bytes[3]
as a pointer to that byte of the variable. But what about atat.wide
? I haven't explicitly passed oneTAT
by reference, so...?
What might actually happen here? It does compile without complaint but I can't test it because the hardware it depends on isn't available yet. Besides, even if it works, I'd like to know why.
And of course, if it's just wrong, how do I best accomplish passing and modifying a variable like this?