byte subkeys[16][48/8];

for (size_t address = 0; address < 16*6; address++)
    Serial.println( (byte) *(subkeys + address) ); 

Why won't the compiler handle this? It tells me

cast from 'byte* {aka unsigned char*}' to 'byte {aka unsigned char}' loses precision [-fpermissive]

If I omit the (byte) part, it tells me

call of overloaded 'println(byte [6])' is ambiguous

I have no idea what's happening.


A byte is to small to store a pointer value. Instead to casting to byte, you should cast to uintptr_t, which is guaranteed to be large enough. On an AVR-based device like the Uno, this is the same as uint16_t or unsigned int, but uintptr_t is more general.

Edit: From your comment it would seem you want to print the contents of the array instead of the addresses of the rows. The obvious way is to loop with two indices:

for (size_t i = 0; i < 16; i++) for (size_t j = 0; j < 6; j++)

If you really want to use subkeys as a 1D array, then cast it to a byte *, which is the type a 1D array would naturally decay to:

for (size_t address = 0; address < 16*6; address++)
    Serial.println(((byte *) subkeys)[address]);
  • But *(subkeys + address) is not a pointer. It is a value in subkeys array. Am I wrong? Feb 10 '16 at 8:34
  • 2
    No, subkeys is an array of arrays of bytes, then *subkeys (as well as subkeys[address], which is a nicer syntax for *(subkeys + address)) is an array of 6 bytes. In most cases, arrays decay to pointers when you use them. You should probably start by telling us what you want to achieve. Feb 10 '16 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.