You say int8 I say char...lets call the whole thing off...
The underlying type will eventually devolve to char because
that's what KnR called a byte in 1972 or thereabouts. int8 (and uint8)
make much more sense in our processor catholic unicoded world,
but they are typedefs in some system header file someplace.
Sorry if my caviler types attitude further confused the issue...
MS
Mikael Ifversen wrote:
Thanks for both replies, it makes sense. But where is "data" declared as
an array of chars. In AM.h the type of the struct TOS_Msg member data,
is int8_t.
Mikael
Michael Schippling wrote:
One slight correction...
> " the corresponding
> bytes from m_msg.data are put into the corresponding fields in the
> variable addressed by the pointer body."
>
Implies that values are copied from m_msg.data to someplace, however
this is not the case. The assignment statement:
CountMsg_t* body = (CountMsg_t*)m_msg.data;
simply sets the "body" variable to the address of the m_msg.data array.
You might think that you need to use &m_msg.data to get the address,
but "data" is declared as an array of chars and C treats the array
name (with no index -- data[1]) as a pointer to the first element.
(I think you might get away with using the &, but it's redundant...)
The key fact is that if you write to body->n you will write into
m_msg.data
If the above makes no sense, probably I'm a bad explainer, but look
at the K&R C book...
MS
Sankar Gorthi wrote:
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
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
.
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help