store 1-dim arrays into 2-dim array

Hi,

I have a function, that requires data in an 1-dim array:

static unsigned char A[] = { 0x0, 0x0,0x7F, 0x0};
Myfunction(A);

Now I want to store different arrays in a 2-dim array:

static unsigned char B[][] = {{0x3E, 0x41, 0x41, 0x3E},{0x0, 0x42, 0x7F, 0x40},{0x62, 0x51, 0x49, 0x46}}
Myfunction(B[1]);

This would work in VB.net, but not in C++.
Anyone an idea, how to do?

Thanks!

This would work in VB.net, but not in C++.

So what goes wrong? Compile error?

First thing would be to use

char B[][4] = ...
static unsigned char B[3][4] = {{0x3E, 0x41, 0x41, 0x3E},{0x0, 0x42, 0x7F, 0x40},{0x62, 0x51, 0x49, 0x46}}
Myfunction(B[1]);

Yes! This is how it works! Maybe the "3" is not needed.

The 3 is not needed. Saves you from modifying it when you add more in the second dimension.

For multi-dimensional arrays, you have one degree of freedom, all other dimensions need to be specified.

PeterVolland:

static unsigned char B[3][4] = {{0x3E, 0x41, 0x41, 0x3E},{0x0, 0x42, 0x7F, 0x40},{0x62, 0x51, 0x49, 0x46}}

Myfunction(B[1]);




Yes! This is how it works! Maybe the "3" is not needed.

The compiler error message seems to make that obvious

forumtest:2:26: error: declaration of 'B' as multidimensional array must have bounds for all dimensions except the first
 static unsigned char B[][] = {{0x3E, 0x41, 0x41, 0x3E}, {0x0, 0x42, 0x7F, 0x40}, {0x62, 0x51, 0x49, 0x46}};