铸造错误:左值要求作为分配的左操作数 [英] Casting Error: lvalue required as left operand of assignment
本文介绍了铸造错误:左值要求作为分配的左操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我试图用 ether_aton()
返回一个结构ether_addr *
。结果
我试图把它放在我的结构ether_header * EPTR
(净/ ethernet.h),它具有 ether_shost
成员。我想这样的:
So I'm trying to use ether_aton()
which returns a struct ether_addr *
.
I'm trying to put this in my struct ether_header *eptr
(from net/ethernet.h) which has the ether_shost
member. I tried this:
struct ether_header *eptr; /* net/ethernet.h */
...
(struct ether_addr*)(eptr->ether_shost) = ether_aton(SRC_ETHER_ADDR);
这给了我错误:因分配的左操作数左值
我知道,我只是无法正常投它,但无法弄清楚如何。
I know I'm just not casting it correctly, but can't figure out how.
编辑:
最终得到它。感谢您的帮助球员。
Ended up getting it. Thanks for the help guys.
struct ether_addr* eth_addr = ether_aton(SRC_ETHER_ADDR);
int i;
for(i=0; i<6; i++)
eptr->ether_shost[i] = eth_addr->ether_addr_octet[i];
就不得不单独分配每个字节的。
Just had to assign each of the octet individually.
推荐答案
您不能施放赋值运算符的左操作数的温度。
You cannot cast the left operand of the assignment operator in C.
这篇关于铸造错误:左值要求作为分配的左操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文