This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

变量的值被修改

昨天遇到zcl_SendRead发送后,抓包看到的目的地址不对的问题,经过调试,发现是目的地址变量的值被修改了,详细如下:

tmpDstAddr.addrMode = (afAddrMode_t)Addr16Bit;
tmpDstAddr.endPoint = 0x01;
tmpDstAddr.addr.shortAddr = 0xC859;     (1)

BasicAttrsList.numAttr = 1;
BasicAttrsList.attrID[0] = ATTRID_BASIC_MANUFACTURER_NAME;  (2)

status = zcl_SendRead( SAMPLESW_ENDPOINT, &tmpDstAddr,
ZCL_CLUSTER_ID_GEN_BASIC, &BasicAttrsList,
ZCL_FRAME_CLIENT_SERVER_DIR, FALSE, bdb_getZCLFrameCounter() );

通过调试发现,代码执行完(1)后,shortAddr的值被正确设定了;当执行完(2)后,shortAddr被修改成了attrID[0](ATTRID_BASIC_MANUFACTURER_NAME)的值。

若是改变代码,交换行1-3和行4-5的顺序(即先设定BasicAttrsList,再设定tmpDstAddr),shortAddr没有问题了,但会出现attrID[0]被修改成shortAddr(0xC859)的值的情况。

也就是说,从结果来看,tmpDstAddr.addr.shortAddr 和BasicAttrsList.attrID[0]互相影响,先执行的会被修改成后执行的值。

tmpDstAddr和BasicAttrsList都是局部变量,都在同一个函数内。

为什么会有这样的问题啊?如何解决?大家帮帮忙~