[英]Type conversion to UInt8 [] from UInt8 gives an error
I've defined a struct like so: 我已经定义了一个这样的结构:
typedef struct __attribute__((packed)) {
UInt8 a;
UInt16 b;
UInt8 c[15];
} myStruct;
When I try to get value 当我尝试获得价值时
UInt8 c = packet->c;
I receive the following error 我收到以下错误
Incompatible pointer to integer conversion initializing 'UInt8' (aka 'unsigned char') with an expression of type 'UInt8 [15]
使用整数类型[UI]的表达式初始化“ UInt8”(即“ unsigned char”)的整数转换的指针不兼容[15]
What type do I need to cast to in order to compile? 我需要强制转换为哪种类型才能进行编译? I have tried adding [15] subscript in different places and could not solve it.
我尝试在不同的地方添加[15]下标,但无法解决。 Also an explanation of what
[15]
means in UInt8 c[15];
还要解释
[15]
在UInt8 c[15];
中的UInt8 c[15];
Thanks 谢谢
I guess packet
is declared as myStruct packet;
我猜
packet
被声明为myStruct packet;
. 。 If so,
packet->c
is an array of UInt8
, you can store up to 15 items in this member. 如果是这样,
UInt8
packet->c
是UInt8
的数组,您最多可以在此成员中存储15个项目。 That's why you cannot assign it's value to a single UInt8
. 这就是为什么您不能将其值分配给单个
UInt8
。 Replace UInt8 c = packet->c;
替换
UInt8 c = packet->c;
with UInt8* c = packet->c;
使用
UInt8* c = packet->c;
. 。 To get the first
c
's item use the following code: UInt8 firstC = c[0];
要获取第一个
c
项,请使用以下代码: UInt8 firstC = c[0];
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.