自定数据结构强制转换为unsigned char类型?
我写了个类型
struct can_header{ //can frame head
canid_t id:11;
canid_t rtr:1;
canid_t ide:1;
canid_t dlc:4;
canid_t eid:18;
};
struct can_frame{
struct can_header header;
unsigned char data[8];
};
希望通过write传给kernel。
struct can_frame *canframe;
canframe=(struct can_frame *) malloc(sizeof(struct can_frame));
memset(canframe,0,sizeof(struct can_frame));
write(fd,(unsigned char *) canframe, sizeof(struct can_frame));
但是没传进去,于是改了
unsigned char str[8] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};
write(fd,str,24);传进去了
kernel中函数是static int mcp251x_write(struct file *file, const char *buf, size_t count, loff_t *ofs)
请问我把canframe指针类型自定义结构强制转换为unsigned char指针类型,用(unsigned char *) canframe为什么不行?谢谢高手指
点。
[解决办法]
这个需要调试了。很可能两个所谓的“write”函数并不相同。