Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 7 months ago.
Array of pointers to byte arrays
typedef unsigned char byte; typedef unsigned int word;
const byte sequence1[] = { 0x11, 0x22, 0x44, 0x88 };
const byte sequence2[] = { 0x01, 0x10, 0x02, 0x20 };
const byte sequence3[] = { 0xFF, 0xDD, 0xEE, 0x44 };
const word sequences[] = { &sequence1, &sequence2, &sequence3 }
How should I declare the sequences array so that it contains the addresses of the three byte arrays?
3 Answers
10 years, 7 months ago.
Took me a few attempts, but what works is:
const byte *sequences[] = { sequence1, sequence2, sequence3 };
Not needed to get the pointer to sequence1, etc, since it is already a pointer to where it is stored. So now it makes an array of byte pointers. Since your byte arrays are the same as byte pointers, that works.
I think that does what you need it to do.
10 years, 7 months ago.
Hello Kevin Callan,
const byte * sequences[] = { sequence1, sequence2, sequence3 };
The variable sequences is an array of pointers to constant unsigned char (byte)
Use this link which "translates" english to declaration or other way around: http://cdecl.org/
As an example, type there : declare sequences as array of pointer to const unsigned char.
Edit: sorry erik, have not seen your answer while typing mine =)
Regards,
0xc0170
10 years, 7 months ago.
@erik, Martin--
Thank you guys! This was not obvious to me. Many thanks.