home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16751 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.2 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!concert!uvaarpa!darwin.sura.net!sgiblab!news.kpc.com!kpc!hollasch
  3. From: hollasch@kpc.com (Steve Hollasch)
  4. Subject: Re: What is meant by: double A[n,m]?
  5. Message-ID: <1992Nov18.223900.8941@kpc.com>
  6. Summary: Confusing, perhaps, but not meaningless.
  7. Sender: usenet@kpc.com
  8. Organization: Kubota Pacific Computer, Inc.
  9. References: <TORSTEIN.92Nov18125146@itekiris.kjemi.unit.no> <28363@castle.ed.ac.uk>
  10. Date: Wed, 18 Nov 1992 22:39:00 GMT
  11. Lines: 39
  12.  
  13. torstein@itekiris.kjemi.unit.no (torstein hansen) writes:
  14. > As a newcomer to C, previously programming in Pascal, I used the
  15. > following declaration in one of my programs:
  16. > double A[n,m];
  17. >
  18. > Has it something to do with the comma operator, discarding the first
  19. > value inside the braces?
  20.  
  21. jlothian@castle.ed.ac.uk (J Lothian) writes:
  22. | I suspect that's exactly what's happening. The comma operator
  23. | evaluates both its arguments, returning the value of the right-
  24. | hand expression and throwing away the value of the left-hand one.
  25. | Presumably your C compiler is quite happy to do this evaluation
  26. | at compile-time, though I'm a little surprised that it didn't flag
  27. | this as an error, given that in this context the construction is
  28. | bound to be meaningless. 
  29.  
  30.     Not true.  First of all, the expression "A[index]" is not evaluated at
  31. compile time, nor is "A[flag,index]"; both of these will be evaluated at
  32. run time.  Nor is this construct meaningless - consider the following
  33. fragment:
  34.  
  35.         return error_msgs [global_errno = ERR_SOMETHING, getindex()];
  36.  
  37. where
  38.         
  39.         error_msgs is an array of pointers to error messages,
  40.         global_errno is some encoded error value,
  41.         and getindex() is a function that returns the error message index
  42.             based on global_errno.
  43.  
  44.     A completely contrived example, but it should demonstrate that using a
  45. comma operator within an array subscript is not meaningless (though some
  46. might object to the above construct for reasons of style).
  47.  
  48. ______________________________________________________________________________
  49. Steve Hollasch                                   Kubota Pacific Computer, Inc.
  50. hollasch@kpc.com                                 Santa Clara, California
  51.