Help with malloc() ...

B. Banerjee bbanerje at sjuvax.UUCP
Sat Aug 18 07:42:50 AEST 1984


Hello,
	I have a similar question which I would appreciate
any solutions to.

I have a large (working) program involving a two dimensional array that
I would like to allocate storage for, dynamically (calloc).  I really
don't want to go through and change all the array references to do
pointer arithmetic.

What I would like to do is something like this -

datum **myarray;	/* datum is typedef'ed */

myarray = calloc(num_rows * num_cols, sizeof(datum));


The trouble is, what should I cast calloc to in order that I may
address myarray using indices?  I thought of doing something like
this :

myarray = (datum **) calloc ( ....)

However, the datum that "myarray[i][j]" would address is not
clear to me.  The situation is even murkier when using higher
dimensioned arrays.

I would be very grateful for any ( and all ) answers.  Please
reply by mail, as I doubt greatly that this is of general
interest.

Regards,

-- 
				Binayak Banerjee
		{allegra | astrovax | bpa | burdvax}!sjuvax!bbanerje
P.S.
	Send Flames, I love mail.



More information about the Comp.lang.c mailing list