home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18978 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.3 KB  |  38 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!wingnut!pauljo
  3. From: pauljo@microsoft.com (Paul Johns)
  4. Subject: Re: Passing 2-d arrys to functions
  5. Message-ID: <1993Jan11.234545.22712@microsoft.com>
  6. Date: 11 Jan 93 23:45:45 GMT
  7. Organization: Microsoft Corp., Redmond, Washington, USA
  8. References: <RUNE.93Jan10125255@pandora.nta.no> <C0Hw4n.Hy9@knot.ccs.queensu.ca> <C0H9sA.BGw@newsserver.technet.sg><24568@alice.att.com> <726521188snx@trmphrst.demon.co.uk>
  9. Distribution: usa
  10. Lines: 26
  11.  
  12. In article <RUNE.93Jan10125255@pandora.nta.no> rune@nta.no wrote:
  13.  
  14. > I'm including a little program that seems to work fine. Here I'm pas-
  15. > sing only the pointer to  a two dimensional array.  Can I expect such
  16. > programs to work, and if so, why?
  17.  
  18. Your program will work.  It is set up correctly.
  19.  
  20. But you are NOT passing the pointer to a two-dimensional array.
  21.  
  22. You are passing the pointer to an array of pointers.  Although
  23. the syntax for accessing an element is the same (x[i][j]), the
  24. underlying data structure is entirely different.
  25.  
  26. Note, for instance, that there's no reason that the row lengths
  27. need to be the same.
  28.  
  29. When you pass a two-diminsional array, you really pass a pointer
  30. to a one-dimensional array (i.e.  TYPE (*p)[ROW_SIZE]; )
  31.  
  32. Your example passes a pointer to a pointer.
  33.  
  34. Check the assembly language generated by the compiler to see the
  35. difference.
  36.  
  37. // Paul
  38.