home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
- From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
- Subject: Re: Small Language Wanted
- Message-ID: <9224105.4487@mulga.cs.mu.OZ.AU>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- References: <H.3lvmyc56w&A@lionbbs.bs.open.de> <17gsgnINN903@network.ucsd.edu> <9224014.17999@mulga.cs.mu.OZ.AU> <1992Aug27.172642.18866@newshost.lanl.gov>
- Date: Thu, 27 Aug 1992 19:30:40 GMT
- Lines: 40
-
- jlg@cochiti.lanl.gov (Jim Giles) writes:
-
- >try:
- >
- > void subroutine(n, m, a[n][m]) {...}
- >
- >Like for writing something as trivial as a matrix multiply routine
- >which can multiply conformable arrays of any size:
- >
- > void mat_mult(i, j, k, a[i][k], b[i][j], c[j][k])
- > {... /* returns `a' since arrays are passed by reference */ ...}
- >
- >Actually, this could be done by eliminating a *single* constraint in
- >the C standard - that is, the one which requires array sizes in declarations
- >to be constant-expressions instead of allowing expressions in globals and/or
- >preceeding parameters. I don't have the rationale document in from of me,
- >so I don't know why they left that constraint in (or if the explained at
- >all).
-
- The constraint does make life quite a bit easier for compiler writers, which
- was presumeably the reason it was there in the first place.
-
- There *are* two possible remedies for this, although both have their
- disadvantages. The first one is quite simple: gcc allows exactly the
- construct you refer to. If you are willing to stick to the one compiler
- (which *is* quite portable) then you can write code exactly like the
- above. gcc even allows you to pass the array name before the array dimension,
- so long as you forward-declare the dimension parameter, like thus:
- mat_mult(int i, j, k; /* forward declaration of parameters */
- int a[i][k], int b[i][j], c[j][k], int i, int j, int k);
-
- The other solution is to use a C++ matrix class. Then you don't even need
- to bother passing the dimensions, and you can even use natural mathematical
- notation - ie. a = b * c, instead of mat_mult(i, j, k, a, b, c).
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-