Message-ID: <34DFEA24.12C2@post.comstar.ru> Date: Tue, 10 Feb 1998 09:20:54 +0300 From: Dim Zegebart Reply-To: zager AT post DOT comstar DOT ru Organization: Comstar Ltd. MIME-Version: 1.0 To: Jason Alexander CC: DJGPP Mail List Subject: Re: Dynamically declaring 2-d arrays References: <34DF9744 DOT C7CFDBFE AT ea DOT oac DOT uci DOT edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Jason Alexander wrote: > > Can someone explain to me how to dynamically declare a 2-d array? > I know the following code works for dynamically declaring a 1-d array > of integers, but I don't see how to extend it to the 2-d case. > > int main(void) { > int i; > int *array; > > printf("Array dimension: "); > scanf("%d", &i); > array = (int *) malloc(i*sizeof(int)) > } GCC has special feature which allows to declare arrays dynamically : int foo(ibt x,int y) { int arr[x][y]; ... } That's all. Note, this is a specific gcc feature, so it's not portable to other compilers. -- ____ ____ | \ / Dim Zegebart ____/____ Moscow Russia WWW - http://www.geocities.com/siliconvalley/pines/7817 DZcomm - comm library for Allegro Palantir - multytasking kernel for Allegro (based on PDMLWP)