Question

Is it possible to see the content of a dynamically allocated array, as in:

int *array = new int[dimension];

I only see the value of the pointer.

edit: just found the option "display as an array", but I always have to manually enter the size of the array. Is it possible to get that automagically?

Was it helpful?

Solution

in eclipse, to see the content of a dynamically allocated array (for anyone else that stumbles across this question),

  1. make sure you are in the debugging perspective. look for the "variables" window. if you don't see it, click "window" > "show view" > "variables".
  2. right click on the array variable
  3. click display as array
  4. eclipse doesn't know how big your array is, so type 0 for the start index and the number of elements you dynamically allocated for the length.

choose display as array in eclipse

OTHER TIPS

If you want to avoid having to repeatedly do "Display As Array", open the "Expressions" tab and add the expression (*array@dimension). Not sure why the parentheses are necessary. Without them you'd get an error.

In the "Expressions" tab, if you do what cleong noted and type (*array@dimension) then you can dynamically set the size of the array to display as well. This even works when you need another expression to get it.

So say you have a variable x that contains your array size, you type (*array@x) and it'll use the content of x as a dimension.

"x" can also be things like struct contents or pointer dereferences and the like - i.e.

(*array@SomePtrToStruct->x) 

works just fine.

just found the option "display as an array", but I always have to manually enter the size of the array. Is it possible to get that automagically?

That's good. I'd stick with it. Getting the array automatically is not possible in the general case in C or C++, though surely in some trivial cases it could be done (but probably is not, yet--features need to be implemented before they exist, to paraphrase Raymond Chen).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top