Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!ncar!noao!amethyst!organpipe!argus.lpl.arizona.edu!ron From: ron@argus.lpl.arizona.edu (Ron Watkins) Newsgroups: comp.lang.c Subject: Re: dynamically define 2-D array Keywords: c, dynamic, array, pointers Message-ID: <357@organpipe.UUCP> Date: 31 Oct 90 14:43:47 GMT References: <1990Oct31.015714.21409@engin.umich.edu> Sender: news@organpipe.UUCP Organization: Lunar and Planetary Lab, U of AZ Lines: 34 If your question is how to declare such a beastie, try this on for size: (please note that im just typing this in from my head not from some existing piece of code); int i; DTYPE ** foo; ... foo = (DTYPE **) malloc (NAXIS2 * sizeof (DTYPE *)); for (i = 0; i < NAXIS2; i++) foo[i] = (DTYPE *) malloc (NAXIS1 * sizeof (DTYPE)); /* OR */ * (foo + i) = (DTYPE *) malloc (NAXIS1 * sizeof (DTYPE)); Where: 1) DTYPE is your data type of interest. If you want multiple data type capability, good luck. Maybe someone would be kind enough to enlighten both of us on that one. 2) NAXIS1 is the fastest axis (note that you can't go zipping through this two dimensional space with a pointer dereference like when you normally declare 2-D arrays). 3) NAXIS2 is the slower axis (presumably y?). I supplied to different approaches for the body of the for loop. Please don't use BOTH of them. :-) P.S. If I have totally screwed this thing up, no flames please. Just nicely tell me that I should go crawl under a rock! Oh and while your doing that, please do send a proper response to the question at hand. _ PEACE! / | \ Ron Watkins / | \ ron@argus.lpl.arizona.edu ( /|\ ) \ / | \ / \ | /