简体   繁体   中英

How can i display a C-style array in visual studio watch without showing its address

I'm looking for a easy way to display a C-style-array in the visual studio watch window without showing its address.

Unfortunately, the format specifier na does only cover pointers.

Fe see this array definition

int a[] = { 1,2 };

在此处输入图像描述

Maybe it's obvious but an easy workaround the somewhat narrow definition of na is to cast to a pointer. For the example in the question:

在此处输入图像描述

The only drawback is that the array length has to be specified manually and that it's way too expressive.

However, what's nice is that this also works with natvis :

<?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> 
  <Type Name="S">
    <DisplayString>a={(int*)a,2na}</DisplayString> 
  </Type>
</AutoVisualizer>

在此处输入图像描述

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