Hi,
I noticed something strange in the CAN_receive function of the RTL ARM library.
When you look at the CAN_pull function, it returns a pointer CAN_Msg object , but that has just been deallocated at the end of the function !!!
So you can always used a object deallocated by the _free_box function ?
static CAN_ERROR CAN_pull (U32 ctrl, CAN_msg *msg, U16 timeout) { CAN_msg *ptrmsg; U32 ctrl0 = ctrl-1; /* Controller index 0 .. x-1 */ /* Wait for received message in mailbox */ if (os_mbx_wait (MBX_rx_ctrl[ctrl0], (void **)&ptrmsg, timeout) == OS_R_TMO) return CAN_TIMEOUT_ERROR; /* Copy received message from mailbox to address given in function parameter msg */ *msg = *ptrmsg; /* Free box where message was kept */ if (_free_box (CAN_mpool, ptrmsg) == 1) return CAN_DEALLOC_MEM_ERROR; return CAN_OK;
No, it is not strictly equivalent.
It depens on what language you are using. In C, the two can be see as equivalent, but if using C++, the assign operator may beform a lot of extra work, depending on operator overloading.