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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!sunic!ugle.unit.no!ugle.unit.no!torstein
  3. From: torstein@itekiris.kjemi.unit.no (torstein hansen)
  4. Subject: What is meant by: double A[n,m]?
  5. Message-ID: <TORSTEIN.92Nov18125146@itekiris.kjemi.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Organization: Dept. of Chem.Eng, Norwegian Inst. of Tech
  8. Date: 18 Nov 92 12:51:46
  9. Lines: 43
  10.  
  11. As a newcomer to C, previously programming in Pascal, I used the
  12. following declaration in one of my programs:
  13.  
  14. double A[n,m];
  15.  
  16. I assumed (erronously) that this would give a n by m matrix. But
  17. obviously, it didn't.  But the compiler never gave any errors or
  18. warnings, and using 
  19.  
  20.   A[rownumber,colnumber]=some_value;
  21.  
  22. was also accepted by the compiler.  I'm not asking for the correct 
  23. way to define an array, I found that out quickly, but what is meant 
  24. by A[n,m]?  It seems like the compiler just ignores the n and makes 
  25. it A[m].  This is also the case when assigning values to the array.
  26.  
  27. That is:
  28.   double A[2,2];  
  29. gave same result as 
  30.   double A[2];
  31.  
  32.   A[0,1] = some_value;
  33. gave same result as
  34.   A[1,1] = some_value;
  35. and 
  36.   A[1] = some_value;
  37.  
  38. Can somebody enlighten me in this matter?  I couldn't find anything
  39. about it in any of the C books I have.  If double A[n,m] is illegal,
  40. shouldn't I get a warning at least?
  41.  
  42. Has it something to do with the comma operator, discarding the first
  43. value inside the braces?
  44.  
  45. By the way, the compiler I used was Turbo C++ ver. 3.1, just in case
  46. this behaviour isn't standard.
  47.  
  48.  
  49. Torstein Hansen
  50. torstein@itekiris.kjemi.unit.no
  51. --
  52. Torstein Hansen
  53. torstein@itekiris.kjemi.unit.no
  54.