Thread: Matrix on stack to int**... How?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by matsp View Post
    Well, technicaly, you can pass a stack array around using this method:
    Code:
    func(int arr2d[][20], ...) ...
    The problem with any multidimensional arrays is that you do need to know the size of all dimensions besides the left-most one, because all C arrays are essentially 1D arrays, with a suitable calculation to achieve the location of the dimensions. The same applies when you allocate on the heap or if you create a global variable -it is only chunk of linear memory in every case.

    --
    Mats
    Yeah, that's what I meant by Pass the 2d array as a parameter. You can also do this to force the first parameter to be the same:
    Code:
    void func(int (&arr2d)[10][20]);
    This also has the effect of making sizeof(array) be the actual size of the array.
    Last edited by King Mir; 10-11-2007 at 11:52 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  2. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-11-2006, 11:41 PM
  3. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  4. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM