Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing n-dimensional array.

Status
Not open for further replies.

PapaGLP

Technical User
Joined
Jul 19, 2002
Messages
31
Location
US
I need to pass an array into a method but the dimension of the array can vary indefinitely (2D, 3D, . . . , nD) with the functioning of the program. Is there a way to allow the method to accept an array of any dimension and to determine the dimension of the array. thanks
 
to determine the dimentions you would need some other parameter(s) but look at the ... ability. Not sure if you really want to do this or not though. However, if you want to get tricky, you could encode the first n bits of the pointer coming in and always cast it as a void pointer. The actual data would come after the encoding.

void processArray(void* ptr)
{
char* encPtr = (char*)ptr;

int dim1 = *char;
int dim2 = *(char+1);
int dim3 = *(char+2);
etc...

if char* is not large enough for your params, move to short*... if 16 bits is not enough, move to int*. Designate an offset to process the array as. The first dimention that is a zero lets you determine the actual dimentions.

I hope that made sense... it was just a thought but it would allow for a generic multi-dimentional array to be passed in.

Matt
 
edit- replace char, char+1 etc with encPtr + x

Matt
 
Also the ... is ellipses, i didnt forget to type something in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top