Hi,

CountMsg_t is a structure datatype. body is a pointer variable of type CountMsg_t.

n is a field in the structure CountMsg_t and so is src.

when you type cast m_msg.data to the CountMsg_t pointer datatype, depending upon the order in which the values are defined in the structure definition and the size of the variables, the corresponding bytes from m_msg.data are put into the corresponding fields in the variable addressed by the pointer body.

for example:
assume m_msg.data is composed of the following bytes:
48 65 6C 6C 6F

CountMsg_t is defined as follows:
typedef struct CountMsg_t {
        uint8_t src;
        char n[3];
}CountMsg_t;

then the pointer body will point to the following fields and the correspondign values:
body->src = 0x48 = 72
body->n[0] = 'e';
body->n[1] = 'l';
body->n[2] = 'l';
body->n[3] = 'o';

Hope that clears stuff up.

Sankar.

On Sat, 18 Nov 2006 06:56:03 -0600, Mikael Ifversen <[EMAIL PROTECTED]> wrote:

Hi,
Can someone clarify following code for me? It is from the CountSendP component in boomerang:
      CountMsg_t* body = (CountMsg_t*)m_msg.data;
      body->n = m_count;
      body->src = TOS_LOCAL_ADDRESS;

CountMsg_t is a variable of struct CountMsg.
m_msg is a variable of TOS_Msg.
m_msg.data is referring to the data field of TOS_Msg struct.
body is a pointer to the variable CountMsg_t.
I know that m_msg.data = 29 and m_msg.data is being typecast by (CountMsg_t*), but still not sure how to interpret: CountMsg_t* body = (CountMsg_t*)m_msg.data.

Thanks,
Mikael
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help



--
No opera plot can be sensible, for people do not sing when they are feeling sensible. - W. H. Auden

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to