> i try to avoid copying anything than 2 pointers...
swapping pointers is easy; swap pointers to arrays just like you swap any other pointers.
#include <stdio.h>
void swap( int rows, int cols, float (**after)[rows][cols] ,
float (**before)[rows][cols] )
{
float (*temp)[rows][cols] = *after ;
*after = *before ;
*before = temp ;
}
int main()
{
int rows = 3, cols = 4 ;
float one[rows][cols] ; one[0][0] = 1.1 ;
float two[rows][cols] ; two[0][0] = 2.2 ;
float (*p1)[rows][cols] = &one ;
float (*p2)[rows][cols] = &two ;
printf( "%f\t%f\n", (*p1)[0][0], (*p2)[0][0] ) ;
swap( rows, cols, &p1, &p2 ) ;
printf( "%f\t%f\n", (*p1)[0][0], (*p2)[0][0] ) ;
}
this means that you will have to write the array_function in terms of pointers to arrays:
void array_function( int rows, int cols, float (*after)[rows][cols],
float (*before)[rows][cols] )
{
//for some iterations
for(;;)
{
int i, j ;
//for all the elements int the array
for (i=1; i<rows; i++)
for(j=1; j<cols; j++)
(*after)[i][j] = 4 * (*before)[i][j] ;
//afterwards prepare for the next iteration
swap( rows, cols, &after, &before ) ;
}
}