home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3238 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.3 KB  |  52 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: Small Language Wanted
  5. Message-ID: <9224105.4487@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. 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>
  9. Date: Thu, 27 Aug 1992 19:30:40 GMT
  10. Lines: 40
  11.  
  12. jlg@cochiti.lanl.gov (Jim Giles) writes:
  13.  
  14. >try:
  15. >
  16. >   void subroutine(n, m, a[n][m]) {...}
  17. >
  18. >Like for writing something as trivial as a matrix multiply routine
  19. >which can multiply conformable arrays of any size:
  20. >
  21. >   void mat_mult(i, j, k, a[i][k], b[i][j], c[j][k])
  22. >   {... /* returns `a' since arrays are passed by reference */ ...}
  23. >
  24. >Actually, this could be done by eliminating a *single* constraint in 
  25. >the C standard - that is, the one which requires array sizes in declarations
  26. >to be constant-expressions instead of allowing expressions in globals and/or 
  27. >preceeding parameters.  I don't have the rationale document in from of me,
  28. >so I don't know why they left that constraint in (or if the explained at
  29. >all).
  30.  
  31. The constraint does make life quite a bit easier for compiler writers, which
  32. was presumeably the reason it was there in the first place.
  33.  
  34. There *are* two possible remedies for this, although both have their
  35. disadvantages. The first one is quite simple: gcc allows exactly the
  36. construct you refer to. If you are willing to stick to the one compiler
  37. (which *is* quite portable) then you can write code exactly like the
  38. above. gcc even allows you to pass the array name before the array dimension,
  39. so long as you forward-declare the dimension parameter, like thus:
  40.     mat_mult(int i, j, k; /* forward declaration of parameters */
  41.          int a[i][k], int b[i][j], c[j][k], int i, int j, int k);
  42.  
  43. The other solution is to use a C++ matrix class. Then you don't even need
  44. to bother passing the dimensions, and you can even use natural mathematical
  45. notation - ie. a = b * c, instead of mat_mult(i, j, k, a, b, c).
  46.  
  47. -- 
  48. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  49. This .signature virus is a self-referential statement that is true - but 
  50. you will only be able to consistently believe it if you copy it to your own
  51. .signature file!
  52.