Results 1 to 3 of 3

Thread: How to display a 1-d array as a 2-d array?

  1. #1
    Junior Member
    Join Date
    Dec 2007
    Posts
    13

    How to display a 1-d array as a 2-d array?

    As the subject says, I'm trying to figure out how to display a 1-d array as a 2-d array. Sample code:

    int array[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    int (* parr)[3] = (int (*)[3])array;

    Putting in nested for loops with the outer one going from 0-3 and the inner one going from 0-2, I can print out each individual element specifying parr[j][k], (0 <= j <= 3; 0 <= k <= 2).

    In the code I can obviously dive on 'array' and see a 12 element 1-d array. How do I specify displaying 'parr'?

    On a related note, if array/parr contained data that could be visualized, how/what would I pass to $visualize to see the data? A slice of the data?

    Thanks.

    Les

  2. #2
    Senior Member
    Join Date
    Jun 2006
    Location
    Natick MA
    Posts
    145

    Re: [lhartzman] How to display a 1-d array as a 2-d array?

    Hi Les,

    You can do this by casting parr to a 2D array in the variable window. Dive on parr and edit the type field from parr[3]* to parr[3][4]*. Then dive on the value. To $visualize use: $visualize ( *(int[3][4]*)parr) or go to Tools > Visualize in the variable window after changing the variable display to a 2D array.

    I hope this helps.
    Josh Carlson

  3. #3
    Junior Member
    Join Date
    Dec 2007
    Posts
    13

    Re: [Josh-TotalView-Tech] How to display a 1-d array as a 2-d array?

    Thanks Josh. I'll give this a try. On a related note, if I don't have 'parr' declared to cast the 1-d to a 2-d array, would I be able to use the same syntax against 'array'? So is there a way to do the same thing without having to explicitly introduce a new identifier?

    Les

    BTW, I'm trying to get a TV log file sent to you, but I'm still jumping through security hoops!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •