【发布时间】:2019-07-09 00:59:00
【问题描述】:
我已经定义了一个结构
typedef struct {
unsigned short a;
unsigned short b;
} my_struct;
发送节点创建一个结构体 并使用
my_struct my;
packetbuf_copyfrom((void *)&my, sizeof(data_struct));
接收节点访问数据通过
my_struct *my;
my = packetbuf_dataptr();
到目前为止一切顺利。通过尝试访问结构的成员 a 或 b 时
printf("%u", my.a);
我明白了:
“错误:在不是结构或联合的东西中请求成员 'a'。”
如果我传输一个简单的字符串并访问它,一切都很好。
【问题讨论】:
-
使用
printf("%hu", my->a);,因为my_struct.a是unsigned short,而不是unsigned int,而my是my_struct *,而不是my_struct。 -
@EOF:msp430-libc(16 位系统)不支持 %hu。只需 %u 就可以了。
-
您对 my->a 部分的看法是完全正确的。现在可以了。非常感谢!