This:
void foo(uint8_t a[]) { ... }
is a function that takes a uint8_t*
, not an array - arrays are decayed to pointers when used as function arguments. The issue is that an initializer list (like {0x01, 0x02, 0x03}
) cannot be converted to a uint8_t*
.
If what you want is to pass an arbitrary number of uint8_t
s to foo
, the simple solution is to use the new std::initializer_list
void foo(std::initializer_list<uint8_t> a) { ... }
foo({0x01, 0x02, 0x03, 0x04, 0x05}); // OK - a has 5 elems in it
Or you could take a variadic pack and construct an array from it internally:
template <typename... Args,
typename = std::enable_if_t<
all_true<std::is_convertible<Args, uint8_t>::value...>
>>
void foo(Args... elems) {
uint8_t a[] = {elems...};
// ...
}
That has slightly different usage:
foo({0x01, 0x02, 0x03}); // error
foo(0x01, 0x02, 0x03; // OK - a has 3 elems in it