Mail Archives: djgpp/1993/07/13/21:57:20
Mat Hostetter <iclone!mjhostet AT cs DOT unm DOT edu> wrote:
There is no reason to use an array of pointers to the beginning of
lines if you use the proper C types. I believe this does what you want:
#define NROWS 512
#define NCOLS 512
typedef int row[NCOLS];
...
row *my_matrix = (row *) malloc (sizeof (row) * NROWS);
my_matrix[123][456] = 7;
...
------------------------------------------------------------------
This is a good technique to be aware of, but not a general solution to
dynamically allocating 2-D arrays. The problem is that you may not
know NCOLS at compile time. What happens when the image size is, say,
800x600 instead of 512x512? You have to recompile with a new #define.
See ALLOC2D.ZIP for a more general solution.
- JW
- Raw text -