PDA

View Full Version : How to display a 1-d array as a 2-d array?



lhartzman
08-21-2008, 05:05 PM
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

Josh-TotalView-Tech
08-22-2008, 08:17 AM
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.

lhartzman
08-22-2008, 09:50 AM
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!