Works with gcc, not with Arduino. error: taking address of temporary array
It is quite right, using that kind of syntax is not allowed. It's a bit of a pain, but it's ok since there is an alternative method - kind of a "trick" if you will.
That trick is to use a string, not an array. After all, a string is just an array, it's just handled slightly differently by the compiler.
Instead of using {...}
use "..."
and use the hexadecimal character escape sequence \xNN
, such as:
cpaddr(a, "\x00\x10\xFF\xCA\x00\x00\xA2\x7D");
You could even lose your custom function and use a standard library function - memcpy()
:
memcpy(a, "\x00\x10\xFF\xCA\x00\x00\xA2\x7D", 8);
On the 8-bit AVRs you can save RAM by using the progmem variant and the F()
macro:
memcpy_P(a, F("\x00\x10\xFF\xCA\x00\x00\xA2\x7D"), 8);