102-cmpd-narrow.c (636B)
1 /* Compound assignment on narrow targets: char/short. The result is 2 * truncated/sign-extended back into the lvalue's type. */ 3 4 int main(int argc, char **argv) { 5 signed char c = 100; 6 c += 50; /* 150 -> truncated to (signed char) -106 */ 7 if ((int)c != -106) return 1; 8 9 short s = 30000; 10 s += 10000; /* 40000 -> wraps in 16-bit signed: -25536 */ 11 if ((int)s != -25536) return 2; 12 13 unsigned char uc = 250; 14 uc += 10; /* 260 -> wraps to 4 */ 15 if ((int)uc != 4) return 3; 16 17 /* Shift compound */ 18 signed char b = 1; 19 b <<= 2; 20 if ((int)b != 4) return 4; 21 return 0; 22 }