[英]How to get struct array (or pointer) that is part of another struct? in C
In the following code:在以下代码中:
typedef struct
{
uint32_t variable_1;
}struct_1;
typedef struct
{
uint32_t variable_2;
}struct_2;
typedef struct
{
struct_1 struct_1_var;
struct_2 struct_2_var;
}struct_all;
struct_all variable_t[10];
struct_1* struct_1_var; //how to get this to point to an array of struct_1 that's inside variable_t?
Basically, I want to get an struct_1[10] or struct_2[10] that that is part of variable_t[10].基本上,我想获得一个 struct_1[10] 或 struct_2[10],它是 variable_t[10] 的一部分。
You can't, because there isn't an array of either struct_1
s or struct_2
s in variable_t
to point to .你不能,因为没有任数组
struct_1
S或struct_2
S IN variable_t
来点。 There is an array of elements, each of which has a struct_1
and a struct_2
.有一个元素数组,每个元素都有一个
struct_1
和一个struct_2
。
If you want an array of just one type of the other of the values in variable_t
, you'll need to copy them out one at a time into a new array.如果您只需要一个包含
variable_t
其他值的一种类型的数组,则需要一次将它们一个复制到一个新数组中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.