Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!nosc!crash!nkraft From: nkraft@crash.cts.com (Norman Kraft) Newsgroups: comp.lang.pascal Subject: Re: Can I declare an array using a var in the index? Keywords: array Message-ID: <4585@crash.cts.com> Date: 22 Sep 90 17:26:17 GMT References: <1994@ac.dal.ca> Organization: Crash TimeSharing, El Cajon, CA Lines: 28 In article <1994@ac.dal.ca> limoges@ac.dal.ca writes: >I want to write a program which generates 2D arrays of size n x n after n has >been input from the keyboard by the user running the program. I have no experience with the Sun Pascal compiler specifically, but the way Pascal compilers are generally built precludes arrays which are of indeterminate length at compile-time. The usual approach to this problem is to declare pointers to the array element type and allocate memory from the heap at run-time. Have you tried this approach? Several pieces of code have been posted to alt.sources which support this concept, though those are specific to Turbo Pascal. You might even be able to implement a variant of the singly linked list to accomplish the same function. Of course, this means that you must also write all your own routines to get/place elements from/to the dynamically allocated "array". Sort of takes the fun out of it, doesn't it? :) Norm. -------------------------------------------------------------------------- Norman R. Kraft "Things should be as Director, Software Development simple as possible, Postal Buddy Corporation, San Diego, CA but not simpler." INET nkraft@crash.cts.com - Albert Einstein UUCP {hplabs!hp-sdd ucsd nosc}!crash!nkraft --------------------------------------------------------------------------