sign extend for addition and subtraction problems
A carry flags are used is only relevant for unsigned integers.  An overflow flag is only relevant for signed integers.  An ALU doesn't "know" whether signed or unsigned integers are being used, so one or both flags might be set; it is up to the programmer to did which is appropriate.

Carry is propagated throughout all bits of a multi-bit ALU (carry-in, carry-out) as you have shown here, with the final carry flag being the carry-out of the most significant bit (MSB). The overflow bit however is only needed on the MSB of an ALU.

The rules for turning on the overflow flag are:


If the sum of two numbers with the sign bits off yields a result number
with the sign bit on, the overflow flag is turned on.

e.g. 0100 + 0100 = 1000 (overflow flag is turned on)
If the sum of two numbers with the sign bits on yields a result number
with the sign bit off, the overflow flag is turned on.

e.g. 1000 + 1000 = 0000 (overflow flag is turned on)


The overflow flag is the XOR of the carry coming into the sign bit (if
any) with the carry going out of the sign bit (if any).  Overflow happens
if the carry in does not equal the carry out.

In the first example above (0100 + 0100) the carry in is 1 and the carry out is 0, therefore overflow.  In the second example (1000 + 1000) the carry in is 0 and the carry out is 1, again there is overflow.