I am writing in C using the Atmel Studio (AVR-C.)
I have an if statement:
if( (rxProcessing < (rxWritePos-1) ) )
Where rxProcessing
and rxWritePos
are already type uint8_t
.
and I want the result of (rxWritePos-1)
to be an unsigned 8-bit int (so that for example if rxWritePos is 0 then 0-1 = 255.)
I want to be sure that the result of the subtraction there will always be an 8-bit unsigned. How can I convert (or make sure that) the result of (rxWritePos-1)
will always be an unsigned 8-bit int?
I think this will do:
if( (rxProcessing < ((uint8_t)rxWritePos-1) ) )
Note that , and I know that I can convert/cast a variable to uint8_t like this: uint8_t y = (uint8_t) x;
but I want to make sure that the conversion will take place inside of if().