Hi Antonio,

 > In my TinyOS application I have to use together TinyOS variables with
 > type
 > like "uint16_t" and C variables with type like "unsigned int".
 > I see they live together with no problems.
 >
 > Now, my question is: what is the difference between these two types of
 > variables in TinyOS?

In C, int is machine dependent. So depending on the word size of your 
processor, an int might have different sizes. Not sure whether the 
example is actually true: on a MicaZ (using an 8-bit Atmel 
microcontroller) and int might be 8 bits, while on a TelosB (using a 
16-bit MSP430 microcontroller) the size of the int would be 16 bits.

In C, not just NesC, people started to define variable types independent 
of the machine (I think, on a PC you find these things in types.h or 
inttypes.h). They usually look something like uint16 or uint16_t. If you 
look at the actual definition of these types, they just map to the 
corresponding machine dependent types. So uin16_t for MicaZ might be 
mapped to long int while on a TelosB it might be simply mapped to int. 
In any case you have the guarantee that the variable uses exactly 16 bits.

> Are they compatible? 
Apart from issues with the size, they are compatible. See below.

> If I have something like:
> 
> uint16_t var1 = 10;
> unsigned int var2 = var1;
> 
> these values are equals?
Yes, if var2 can hold the value of var1. If var2 was only 8 bits (you'd 
have to check this on a MicaZ), then if the value of var1 was bigger 
than 255, var2 would only hold the 8 least significant bits.

> And if I call a method like this:
> 
> void test(uint16_t var1);
> 
> with the string: 
> 
> test(var2);
> 
> where var2 is an unsigned int?
That should work without any problems. The only issue, again, would be 
if var2 was bigger than 16 bits and had a value that could not be 
represented in only 16 bits, then the value would be truncated (to the 
16 least significant bits).

Cheers,
Urs

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

Reply via email to