[英]Casting a pointer to struct to an array
I have a dynamically allocated array of structs. 我有一个动态分配的结构数组。
I want to cast it to an array type so my debugger will show the whole array. 我想将其转换为数组类型,以便调试器显示整个数组。
Is it possible? 可能吗?
I know that this cast is not a good idea, but it's only a cast for expression evaluation of the debugger. 我知道这个转换不是一个好主意,但这只是调试器的表达式评估的转换。 –
–
Yes. 是。 For example, if you allocated array of 100 elements of type
t_my_struct
then cast pointer to t_my_struct
=> pointer to array of 100 elements of type t_my_struct
: 例如,如果您分配了
t_my_struct
类型的100个元素的数组,则将指针转换为t_my_struct
=>指向t_my_struct
类型的100个元素的t_my_struct
:
t_my_struct * Dynamic = ( t_my_struct * )calloc( 100, sizeof *Dynamic );
t_my_struct (* Static)[ 100 ] = ( t_my_struct (*)[ 100 ] )Dynamic;
Now you can see Static
as static array in debugger. 现在,您可以在调试器中看到“
Static
作为静态数组”。 Works in MSVC. 在MSVC中工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.