Page 1 of 1

array of pointers to arrays???? C/C++

Posted: Thu Dec 23, 2010 10:20 pm
by ramses
Okay. I have 9 character arrays (to reduce memory consumption), each [2][12][12]. I would like to have an array of pointers to those arrays, and use it to pass a specific one of those arrays to a function.

I have tried many things as far as syntax goes.

Code: Select all


void optimize(unsigned char parameter[2][12][12] );

//for the sake of this, lets assume that all these arrays are declared and initialized.

int main()
{
unsigned char *large_tables[9]={&spark_table, &fuel_start_table,  &fuel_duration_table, &water_start_table,
                                      &water_duration_table, &intake_phasing_table, &intake_duration_table,          
                                      &exhaust_phasing_table, &exhaust_duration_table};  

optimize(*large_tables[subsystem]);
}

void optimize(unsigned char parameter[2][12][12] )
{
     // do stuff
}
I'm getting the following errors:

Code: Select all

 warning: array subscript has type 'char'
error: call of overloaded 'optimize(unsigned char&)' is ambiguous
in other configuretions (guessing), I got:

Code: Select all

cannot convert char (*)[2][12][12] to 'char' in initialization
invalid conversion from 'char' to char (*)[2][12][12]'
Any ideas? I would really rather this not be a 4d array, although that may be an option. I'd also rather NOT rewrite the whole program to use pointers with explicit address arithmetic.

Thanks,
Chris

Posted: Thu Dec 23, 2010 11:23 pm
by jrrdw
Post this to Theopia's computer section TurboSuper can help you with this one.

Posted: Fri Dec 24, 2010 10:02 am
by ramses
Thanks. I know there are some resident programmers here. I didn't realize Theopia was actually active.