help converting multi-dim arrays

Kevin Szabo ksbszabo at wateng.UUCP
Sat Apr 6 19:05:53 AEST 1985


In article <569 at utcs.UUCP> you write:
>But, we still want to access the 
>matrices as:
>           ...data[row][col] ...
>Any ideas?
>Dave Harrison, Dept. of Physics, Univ. of Toronto: ..utzoo!utcs!physics

If you only have one matrix that you want to access, how
about:

static double *data;
#define	DATA(row,col)	(*(data + row*numcols + col))

Or if you only have a few, how about a couple of macro's?
You can even adopt the matrix format where the matrix is an array of
pointers.  It's all hidden in the macro.

The nice thing about this is that you could easily implement a sparse
matrix by redefining DATA to be a function or inline code.

#define	DATA(row,col) (*Find_address_of_sparse_array_element(row,col))

			Kevin
-- 
Kevin Szabo  watmath!wateng!ksbszabo (U of Waterloo VLSI Group, Waterloo Ont.)



More information about the Comp.lang.c mailing list