SoLaLa wrote:
> versteh ich jetzt nicht... die Beispiele sind doch alle 3 korrekt, oder
> nicht?
Nein, mathematisch exakt sind sie alle falsch.
Wenn man x anfängt bei 0 zu zählen und immer nur erhöht, kann der Wert
nie wieder 0 sein. Neuere Versionen von gcc erkennen das und optimieren
entsprechend, falls nicht entsprechend beschaltert ist
(-fno-strict-overflow).
gcc release notes state:
> For example, a loop like
>
1 | > for (i = 1; i > 0; i *= 2)
|
2 | >
|
> is presumably intended to continue looping until i overflows.
> With -fstrict-overflow, the compiler may assume that signed overflow
> will not occur, and transform this into an infinite loop.
> -fstrict-overflow is turned on by default at -O2...