gcc knows it better

Imagine you want to know the value of "MAXINT" (or any other type).

As everyone knows when you increment MAXINT the value wraps down to the most negative value and so a+1 will no longer be bigger than a.

So you might come up with this idea:

int a;

void setup() {
  PORTB = 123;
  while (a < a+1) a++;
  PORTB = 234;

void loop() {

(The PORT commands only were added to identify the section inside the compiled code.)

But you will be surprised that there is no output, given that you have added the appropriate print statements.

And when you check the compiled code you will find that the compiler interpreted the source as an endless loop "while (true);". Not even adding a RET instruction at the end of the setup function. The line "PORTB = 234;" is taken as unreachable code and completely ignored.

00000090 <setup>:
  90:	8b e7       	ldi	r24, 0x7B	; 123
  92:	85 b9       	out	0x05, r24	; 5
  94:	ff cf       	rjmp	.-2      	; 0x94 

00000096 <loop>:
  96:	08 95       	ret

So the compiler does not know anything about the wrap behind MAXINT and identifies (a < a+1) equal to TRUE for any value of a.

contact: nji(at)gmx.de