2

I've the following C code that creates a dynamically allocated 2D array.

numbersArray = (int **)malloc(sizeof(int *)* primeNumber);

for (i =0 ; i < primeNumber; i++)
    numbersArray[i] = (int *)malloc(sizeof(int)*2);

numbersArray is globally defined and primeNumber is just a number that I calculate during the execution of the program.

My program performs well without problems. I can do various processes on the array. It works totally fine.

My question is that Xcode 5 doesn't show the contents of numbersArray when debugging. It just shows the following:

Debug area in Xcode 5

Why can't it display the dynamically allocated array properly that I would be able to see each and every cell in the array?

I checked similar questions before posting this and they talked about dynamic allocation that the compiler isn't aware of the array size(s) until runtime but I think I remember that before(in previous versions of Xcode) I was able to see the contents of a dynamically allocated array.

What's really going on here? Has it been always like this or is it an Xcode 5 thing or maybe I have the configure Xcode?

1 Answer 1

1

First, please don't cast the return value of malloc() in C.

Now, I think you mis-remember. Unless it's doing pretty advanced analysis, there should be no way for the debugger to know that an int ** variable should be interpreted as an array of a specific size.

What you can often do, is use various "view memory as ..."-type commands to inspect the memory. This will be even more complicated by the fact that your array is "jagged", i.e. each row is a pointer to that rows's data rather than the entire array being a single contiguous allocation.

Sign up to request clarification or add additional context in comments.

2 Comments

OP could check the return value of malloc too.
Yeap, guess I misremember. Thanks for the tip. Also could you please share some commands to inspect the memory. Like how can I inspect a double array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.