Path: utzoo!attcan!uunet!mailrus!sharkey!cfctech!teemc!mibte!gamma!towernet!uts!judah From: judah@uts.uucp (Judah Greenblatt) Newsgroups: comp.lang.c Subject: Dynamically allocated multi-dimensional arrays Message-ID: <124@towernet.UUCP> Date: 20 Nov 89 14:12:18 GMT Sender: netnews@towernet.UUCP Lines: 39 I've recently been playing around with dynamically allocated multi-dimensional arrays in C. So far I've found two ways to handle them: * As a one-dimensional array, using a macro to do the subscript calculations: double *a; a = (double *)malloc(rows * cols * sizeof(double)); #define Sub(a, x, y) ((a)[(x) * cols + (y)]) d = Sub(a, i, j); This involves no extra space, no extra memory references, but looks ugly. * As an array of pointers to arrays: double **a; a = (double **)malloc(rows * sizeof(double *)); for (i=0; i