No, you cannot assign C-style arrays like that.
What you wrote means: assign the (nonexistent) seventh element of the MAC address with index macIndex
in macs
to the (nonexistent) seventh element of the array mac_addr_Server_Used`.
(The arrays have length 6, so the maximum index you can access is 5.)
In this case, it might make sense to store a pointer to the MAC address instead of storing a copy:
uint8_t macIndex = 2;
const uint8_t macs[][6] = {
{0x34, 0xb4, 0x72, 0x4d, 0x63, 0xc6 },
{0xb0, 0x7e, 0x11, 0xdd, 0xc7, 0x97 },
{0x01, 0x02, 0x03, 0xdd, 0xc7, 0x97 },
};
const uint8_t (*mac_addr_Server_Used)[6] = nullptr;
void setup() {
mac_addr_Server_Used = &macs[macIndex];
// use *mac_addr_Server_Used
}
Unless you're using an AVR board, use a C++ std::array
instead of a C-style array: they can be copied without any problem, and resolve most of the issues with C-style arrays.
#include <array>
uint8_t macIndex = 2;
using mac_t = std::array<uint8_t, 6>;
const mac_t macs[] = {
{0x34, 0xb4, 0x72, 0x4d, 0x63, 0xc6 },
{0xb0, 0x7e, 0x11, 0xdd, 0xc7, 0x97 },
{0x01, 0x02, 0x03, 0xdd, 0xc7, 0x97 },
};
void setup() {
mac_t mac_addr_Server_Used = macs[macIndex];
// use mac_addr_Server_Used
}