Variable-Length Array Parameters in NCEG C

James Frankel uunet!Think.COM!frankel
Mon Jul 6 15:00:24 PDT 1992


   From: Conor O'Neill <conorainmos.co.uk>
   Date: Mon, 6 Jul 92 11:26:35 BST

   Richard Stallman writes:
   >Compiler writers should do "the work" once--but they should do the
   >right work, not the wrong work.  They should implement a language that
   >has a clean definition.  A language whose features work all the time,
   >not just most of the time.  A language whose meaning is very easy to
   >predict.

   He then adds, in another article:
   >>            b[n*n, 3*m + p]
   >Using the syntax I proposed, this does not cause a problem.
   >The prototype would look like this:
   >
   >void a (int n; int m; int p; float b[n*n, 3*m + p], int n, int m, int p);

   I would say that this most definitely _does_ cause a problem.
   This prototype is extremely unclear about what order the parameters are.
   I would not consider this to be a "language whose meaning is very easy to
   predict", and certainly not a language which is easy to read.

I presume the above examples were supposed to be:

void a(int n; int m; int p; float b[n*n][3*m + p], int n, int m, int p);

(Notice the change in the square brackets.)

I agree that the syntax makes it difficult to find the formal parameters that
are not just forward declarations.  Stallman sees appropriate formatting of
the program as the solution to this problem.  For example, the declaration
above could be written as:

void a(int n; int m; int p;
       float b[n*n][3*m + p], int n, int m, int p);

I have proposed the following solution.  A definition would look like:

void a(b[*][*], int n, int m, int p)
float b[n*n][3*m + p];
{
}

where the asterisks within the parentheses could be any symbol on which
enough people agree.  This proposal has the advantages of keeping the
formal parameter list straightforward and simple, while leveraging off the
syntax for unprototyped functions to complete the declaration of "b".

The prototyped declaration would simply look like:

void a(b[*][*], int n, int m, int p);

If it is found to be objectionable that the old style parameter declaration
syntax is being used to complete the declaration of prototyped parameters,
the declaration of "b" could be included within the parameter declaration
parentheses as follows:

void a(b[*][*], int n, int m, int p;; float b[n*n][3*m + p]);

This proposal still requires an asterisk or some other placeholder in the
forward declaration of "b", but it has the formal parameters appear first
and in the correct order before the declaration of arrays are made complete.
The ";;" symbol could be changed to some other agreeable character or
sequence of characters.

Comments please?

Jamie

----------

James L. Frankel
Senior Scientist
Thinking Machines Corporation
245 First Street
Cambridge, MA   02142-1264
U. S. A.

(617) 234-2754
Enet: FrankelaThink.COM



More information about the Numeric-interest mailing list