views:

75

answers:

2

I'm having trouble figuring out how to declare a pointer to an array of arrays of void*. (I can't use STL containers and the like because it's an embedded system.)

I have some data that I'm trying to group together in a structure. Mostly built-in data types, but then are these two arrays. The first one,

char *testpanel_desc[] = {...};

isn't a problem. In my structure I store a pointer to this array like so:

struct MyStruct
{
    ...
    char** panelDesc;
};

But then there's this one:

 void *testpanel_pointers[][4] = {...};

and I can't come up with a way to define a member of my structure that I can assign this array to. void*** doesn't work because of the 4 in the original declaration.

+3  A: 

Make life a bit simplier and use typedefs

identity<void*[4]>::type *panelDesc;

Or equivalent

typedef void *type[4];
type *panelDesc;

I doubt you know what the following means, but suffice it to say it's equivalent too

void *(*panelDesc)[4];

Note that based on type, it is not a "a pointer to a two dimension array of void*", much like char** is not a "pointer to a one dimension array of char*". But keeping the way you do it in the one-dimension case (pointing to the first element), this is the declaration you need.

Johannes Schaub - litb
Thanks. I wasn't considering the problem in such terms (pointer to the first element), even though it makes perfect sense when you think about it a bit.
dandan78
+2  A: 
void *testpanel_pointers[1][4] = {};

void* (*p)[1][4]; //pointer to a two dimensional array of pointers to void
p = &testpanel_pointers;
Prasoon Saurav