You shouldn't need to cast them at all, the rules in C relating to implicit promotions should take care of that for you.
In other words, comparing an unsigned char
to an unsigned int
will first promote the unsigned char
to be compatible, then do the comparison.
It's all covered in C99 6.3.1.8 Usual arithmetic conversions
which states (after discussing floating point types):
Otherwise, the integer promotions are performed on both operands.
Then the following rules are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.
Otherwise, if both operands have signed integer types or both have unsigned
integer types, the operand with the type of lesser integer conversion rank is
converted to the type of the operand with greater rank.
... and so on, but that last paragraph above is the applicable one.
If the types are as you've stated and Data[2]
actually is the same value as what's returned from ReadFlash2(40)
, then it's not a C environment, at least not according to the standard.