We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Below is a code Snippet:
I am trying to pass pointers through a function; And I am trying to get back the results. Does not work at this time?
main() {
static UCHAR ucRcvAddress, *ucMBFrame, usLength;
eStatus = eMBRTUReceive( &ucRcvAddress, &ucMBFrame, &usLength );
}
eMBErrorCode eMBRTUReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) { BOOL xdata xFrameReceived = FALSE; eMBErrorCode xdata eStatus = MB_ENOERR; UCHAR test = 5;
ENTER_CRITICAL_SECTION(); assert( usRcvBufferPos < MB_SER_PDU_SIZE_MAX );
if( ( usRcvBufferPos >= MB_SER_PDU_SIZE_MIN ) && ( usMBCRC16( ( UCHAR * ) ucRTUBuf, usRcvBufferPos ) >= 0 ) ) { *pusLength = ( USHORT )( usRcvBufferPos - MB_SER_PDU_PDU_OFF - MB_SER_PDU_SIZE_CRC );
*pucFrame = ( UCHAR * ) & ucRTUBuf[MB_SER_PDU_PDU_OFF]; xFrameReceived = TRUE; } else { eStatus = MB_EIO; } EXIT_CRITICAL_SECTION( ); return eStatus; }
I am trying to pass a pointer to capture an array[] then pass it back.
Phil
If I have a defined pointer, like *ucMBFrame.
I should be able to pass this as an argument to a function like eMBError Receive( &ucMBFrame);
on the other side I should be able to capture first position of the array.
Receive( **pucFrame) { *pucFrame = &ucMBRTUBuf[Buf_Size]; }
and return it to calling function.
The results should be first position of char ucMBRTUBuf[Buf_Size];
and if I went -- data = *ucMBFrame[1]; I should see second char in the array?
"The results should be first position of char ucMBRTUBuf[Buf_Size];"
No, assuming Buf_Size is as it's named, the result would be the address just past the end of the array.