Hi Everyone,
In assembly when you add a number to another number, you have the carry flag to detect if the add resulted in an overflow.
In C, what is the best/most optimal way to do the same?
Let's say we have two:
uint8_t c1,c2;
And then we add them:
c1+=c2;
One way is to use a larger variable, or count on C taking these uint8_t up to a uint16_t:
if (c1+c2>=256)
overflow=1;
else overflow=0;
c1+=c2;
That seems less than optimal and what if c1/c2 are scaled to 16 or 32 bits...
What thoughts do you guys have?