请大家指点一下:
在OSAL.h中有如下两个结构体:
typedef struct {
void *next;
uint16 len;
uint8 dest_id;
} osal_msg_hdr_t;
typedef struct {
uint8 event;
uint8 status;
} osal_event_hdr_t;
在peripheral.c中,有如下语句:
uint16 GAPRole_ProcessEvent( uint8 task_id, uint16 events ) {
VOID task_id; // OSAL required parameter that isn't used in this function
if ( events & SYS_EVENT_MSG )
{ uint8 *pMsg;
if ( (pMsg = osal_msg_receive( gapRole_TaskID )) != NULL )
{
gapRole_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );
。。。。。
}
static void gapRole_ProcessOSALMsg( osal_event_hdr_t *pMsg )
{
switch ( pMsg->event )
{ case GAP_MSG_EVENT:
gapRole_ProcessGAPMsg( (gapEventHdr_t *)pMsg );
。。。
}
osal_msg_receive函数return (uint8*) foundHdr ,而 foundHdr 是 osal_msg_hdr_t * 型的。
所以在pMsg = osal_msg_receive( gapRole_TaskID )后,pMsg是一个uint8 *型的指向有那么一个结构
{
void *next;
uint16 len;
uint8 dest_id;
}
的指针,该结构的长度为sizeof(void *)+2+1个字节;
gapRole_ProcessOSALMsg( (osal_event_hdr_t *)pMsg );语句后,pMsg变成了指向osal_event_hdr_t结构体的指针,该结构为
{
uint8 event;
uint8 status;
}共两个字节;
请问:
pMsg的值并没有改变,它指向的还是同一个存储块,但是
{
void *next;
uint16 len;
uint8 dest_id;
}却变成了
{
uint8 event;
uint8 status;
}完全是不一样的数据结构
那在 gapRole_ProcessOSALMsg函数中的 pMsg->event ,这event是怎么变来的,我想不明白,请大家给我指点一二,感激不尽