[Tinyos-devel] One should make limited use of the "%" operator

Philip Levis pal at cs.stanford.edu
Thu Jun 25 15:28:18 PDT 2009


On Jun 25, 2009, at 2:54 PM, Michael Newman wrote:

>
>
> 2) Phil's strategy is ONLY a good idea if idx is an 8 bit integer.  
> If the
> data type is a 16 bit or 32 bit integer this code could result in a  
> loop
> that takes an unexpectedly long time to execute.
>>
>> or
>>
>> while (idx > QUEUE_SIZE)
>>   idx -= QUEUE_SIZE;
>>

Right -- I'm sorry, I read the code so quickly I didn't actually read  
it. I assumed

if (idx >= QUEUE_SIZE)
   idx -= QUEUE_SIZE;

If you look, that's what I committed.

Phil



More information about the Tinyos-devel mailing list