Skip to main content
Arduino

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

See Using array init list as temporary in C++11? Using array init list as temporary in C++11?

You can solve it by using const. This compiles:

char a[8];
void cpaddr(char target[], const byte *source) {
 int i;
 for (i=0; i<8; i++)
 target[i] = source[i];
}
int main() {
 byte b[] = {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D};
 cpaddr(a, b);
 cpaddr(a, (const byte[]) {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D});
}

Note I had to change your array from char to byte because I was getting (valid) warnings that things like 0xCA don't fit into a char.

See Using array init list as temporary in C++11?

You can solve it by using const. This compiles:

char a[8];
void cpaddr(char target[], const byte *source) {
 int i;
 for (i=0; i<8; i++)
 target[i] = source[i];
}
int main() {
 byte b[] = {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D};
 cpaddr(a, b);
 cpaddr(a, (const byte[]) {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D});
}

Note I had to change your array from char to byte because I was getting (valid) warnings that things like 0xCA don't fit into a char.

See Using array init list as temporary in C++11?

You can solve it by using const. This compiles:

char a[8];
void cpaddr(char target[], const byte *source) {
 int i;
 for (i=0; i<8; i++)
 target[i] = source[i];
}
int main() {
 byte b[] = {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D};
 cpaddr(a, b);
 cpaddr(a, (const byte[]) {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D});
}

Note I had to change your array from char to byte because I was getting (valid) warnings that things like 0xCA don't fit into a char.

Source Link
Nick Gammon
  • 38.9k
  • 13
  • 69
  • 125

See Using array init list as temporary in C++11?

You can solve it by using const. This compiles:

char a[8];
void cpaddr(char target[], const byte *source) {
 int i;
 for (i=0; i<8; i++)
 target[i] = source[i];
}
int main() {
 byte b[] = {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D};
 cpaddr(a, b);
 cpaddr(a, (const byte[]) {0x00, 0x10, 0xFF, 0xCA, 0x00, 0x00, 0xA2, 0x7D});
}

Note I had to change your array from char to byte because I was getting (valid) warnings that things like 0xCA don't fit into a char.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /