简体   繁体   中英

Unable to view arrays in Visual Studio C++ debugger?

I have the following code:

char *DecompressChunk(Node *startNode, int arraySize)
{
    char *cubeArray = new char[arraySize];

When I put a breakpoint down after that, with arraySize being 18, when I hover over the array to try and view it, only the first element shows up and nothing else, I can print them and it works fine but I cannot view them all with VS. How do you set it so you can view all of them, or can you?

You can tell the debugger how large the array is by adding a comma followed by the size in the watch window (this is called a format specifier):

cubeArray,18

You can't use a variable or anything as the array size.

Here are some other tricks .


This doesn't help if you just want the tool-tips to show you more; it can only be used in watch windows.

Although Microsoft probably could improve tool-tips for arrays in some special cases, in general it would be very difficult due to the nature of arrays in C++; pointers to elements of an array have no way to know the bounds of that array. The effect this has on the debugger is probably one of the least significant problems. Other problems this creates impact the security and correctness of programs.

If you avoid raw arrays in favor of smarter types then the debugger can provide better tool-tips. The debugger already knows how to display std::vector , for example.

You can use a variable as a size for a dynamic array

for instance

int* x = new int [size];

The created array must be manually deallocated via:

delete[] x;

Now back to the op, I dont see a reason why all of them would not be displayed unless they havent been created yet, or VS may be incapable of recognizing the difference between a normal pointer and an array pointer, they are seen by the computer as the same thing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM