Einzelnen Beitrag anzeigen

Assertor

Registriert seit: 4. Feb 2006
Ort: Hamburg
1.296 Beiträge
 
Turbo C++
 
#23

AW: Achtung. Optimierung beim Compiler

  Alt 10. Jun 2010, 17:40
Hallo,

i ist im weiteren verlauf mein index auf ein anderes Array.
p80286 und himitsu haben absolut recht: Der Wert der Schleifenvariable ist nach der Schleife nicht garantiert, egal was Du machst. Um die Eingangsfrage zu beantworten: Ja, das Verhalten ist bekannt.

Die Herren Nick Hodges, Allen Bauer und Primoz Gabrijelcic schreiben es bei StackOverflow so:

Zitat:
That is correct. The variable is specifically documented to be undefined after the loop is complete. If you need a defined variable after the loop, use while or repeat – Nick Hodges Apr 9 at 22:45

Depending upon how the loop variable is used within the loop, the compiler may even eliminate it completely and simply use a pointer to iterate through the elements of an array, for example. – Allen Bauer Apr 10 at 0:02

... is undefined ... except if you terminate the loop with the 'break' statement. In that case, value is defined (the last value the loop counter had before the 'break' was executed). – gabr Apr 10 at 5:57
Der Sonderfall Break bzw. Exit wird von Gabrijelcic angerissen, in der Delphi Hilfe bzw. Daniels Delphi Referenz darauf wird das im Detail erörtert.

Gruß,
Assertor
Frederik
  Mit Zitat antworten Zitat