home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #23 / NN_1992_23.iso / spool / vmsnet / internal / 1417 < prev    next >
Encoding:
Text File  |  1992-10-09  |  2.5 KB  |  55 lines

  1. Newsgroups: vmsnet.internals
  2. Path: sparky!uunet!pipex!pavo.csi.cam.ac.uk!cam-cl!rf
  3. From: rf@cl.cam.ac.uk (Robin Fairbairns)
  4. Subject: Re: C Language question
  5. Message-ID: <1992Oct8.134446.3531@infodev.cam.ac.uk>
  6. Sender: news@infodev.cam.ac.uk (USENET news)
  7. Nntp-Posting-Host: ely.cl.cam.ac.uk
  8. Reply-To: rf@cl.cam.ac.uk (Robin Fairbairns)
  9. Organization: U of Cambridge, England
  10. References: <23000B53_00073190.00961C83B1DAD300$668_1@UK.AC.KCL.PH.IPG>
  11. Date: Thu, 8 Oct 1992 13:44:46 GMT
  12. Lines: 41
  13.  
  14.  
  15. In article <23000B53_00073190.00961C83B1DAD300$668_1@UK.AC.KCL.PH.IPG>,
  16. SYSMGR@IPG.PH.KCL.AC.UK writes:
  17. |> (To those who get offended by questions that stray outside a group's main
  18. |> intention - Sorry, please hit delete now. I'm not sure what the appropriate
  19. |> mail list is, and I do know that the folks that follow this one are likely
  20. |> to know!)
  21.  
  22. Sure as hell is the wrong group - you need comp.lang.c or somesuch.
  23. However, it may not be available as a mailing list: get yourself
  24. Usenet news, Nigel!
  25.  
  26. |> Question: in C, if one declares char a[I][J], is there anything in the
  27. |> language standard that guarantees that &a[0][0] is the first of a set of
  28. |> I*J contiguous chars, and that a[i+1][0] is guaranteed to be the same
  29. |> storage location as a[i][J] ).
  30.  
  31. The standard (actually I only have a copy of the 1st DIS, but it's
  32. hardly likely to have changed) says "... The definition of the
  33. subscript operator [] is that E1[E2] is identical to (*(E1+(E2))).
  34. ..."  It then goes on to say "... If E is an n-dimensional array
  35. (n>=2) with dimensions ixjx...xk, then E (used as other than an
  36. lvalue) is converted to a apointer to an (n-1)-dimensional array with
  37. dimensions jx...xk.  If the unary * operator is applied to this
  38. pointer explicitly, or implicitly as a result of subscripting, the
  39. result is the pointed-to (n-1)-dimensional array, which is itself
  40. converted to a pointer if used as other than an lvalue.  It follows
  41. from this that arrays are stored in row-major order (last subscript
  42. varies fastest)."
  43.  
  44. I think that answers your question
  45.  
  46. |> A friend asserts that it is, and says his experience on several systems
  47. |> 'proves' this. My belief is that there is nothing that says this will
  48. |> always be the case, and that the only constraint is that every valid pointer
  49. |> a[i] will point to J chars. Which of us is right?
  50.  
  51. Your friend is obviously neither a scientist nor a mathematician ;-)
  52. --
  53. Robin (come back John Drummond) Fairbairns       rf@cl.cam.ac.uk
  54. U of Cambridge Computer Lab, Pembroke St, Cambridge  CB2 3QG, UK
  55.