procedure a(fname: array[lo..hi:integer] of char);
The data names lo and hi (or whatever you called them) get filled in with the
corresponding array bounds from the actual parameter in each call. Experience has shown
that many programmers find this confusing. In solving for the general case, the language
designers also made the simplest case of literal fixed array bounds illegal:
1 procedure a(fname: array[1..70] of char);
E --------------------------^--- Expected identifier
This aspect of the language definition clearly runs counter to the expectations of many
programmers, and generates numerous support calls to this day. We regularly get an
escalation about this "Pascal compiler bug" every couple of months on the Sun compiler
team. There are other problems with Pascal-conformant arrays; for example, a conformant
array of characters does not have string type (because its type isn't denoted by an array
type), so even though it is an array of characters, it cannot be used where a string is
expected! Conformant formal array parameters cause more grief for Pascal programmers
than just about anything else, except maybe interactive I/O. Worse still, some people are
now talking about adding conformant arrays to C.
Attempt 3
The third possibility is to give up on two-dimensional arrays and change the organization to an Iliffe
vector; that is, create a one-dimensional array of pointers to something else. Think of the parameters
of the main routine. We are used to seeing char * argv[]; and even sometimes char **
argv;, reminding ourselves of this makes the notation easy to unscramble. Simply pass a pointer to
the zeroth element as the parameter, like this (for a two-dimensional array):
my_function( char **my_array );
But you can only do this if you first change the two-dimensional array into an array of
pointers to vectors!
The beauty of the Iliffe vector data structure is that it allows arbitrary arrays of pointers to strings to be
passed to functions, but only arrays of pointers, and only pointers to strings. This is because both
strings and pointers have the convention of an explicit out-of-bound value (NUL and NULL,
respectively) that can be used as an end marker. With other types, there is no general foolproof out-of-
bound value and hence no built-in way of knowing when you reach the end of a dimension. Even with
an array of pointers to strings, we usually use a count argc of the number of strings.
Attempt 4
The final possibility is again to give up on multidimensional arrays, and provide your own indexing.
This roundabout method was surely what Groucho Marx had in mind when he remarked, "If you stew
cranberries like applesauce, they taste more like plums than rhubarb does."