Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!uvaarpa!mcnc!ncsuvx!csl!harish From: harish@csl.ncsu.edu (Harish Hiriyannaiah) Newsgroups: comp.lang.c Subject: Re: Style for handling matrices in C Message-ID: <4204@ncsuvx.ncsu.edu> Date: 17 Oct 89 02:01:27 GMT References: <7229@cognos.UUCP> <278@dsi.COM> Sender: news@ncsuvx.ncsu.edu Reply-To: harish@csl.UUCP (Harish Hiriyannaiah) Organization: North Carolina State University Lines: 29 In article <278@dsi.COM> dave@dsi.UUCP (Dave Rifkind) writes: -Here's one that doesn't require any special action to free up the -matrix: - - double **mat_alloc(row, col) - { - int i; - double *dp, **dpp; - - dpp = malloc(row * sizeof(double *) + row * col * sizeof(double)); - if (dpp != NULL) { - dp = dpp + row; - for (i = 0; i < row; i++) - dpp[i] = dp + i * col; - } - return dpp; - } Here you are assuming that the pointers are word aligned, which can be pretty dangerous..... Consider, for example short pointers to floats. If we have 7 rows (or any odd number), then the allocated space for the first float will fall on a 16-bit boundary..... harish pu. hi. harish@ecelet.ncsu.edu harish@ecebucolix.ncsu.edu