Ja. Der C11-Standard sagt in § 6.5:
If a side effect on a scalar object is unsequenced relative to either a different
side effect on the same scalar object or a value computation using the value of the
same scalar object, the behavior is undefined. If there are multiple allowable
orderings of the subexpressions of an expression, the behavior is undefined if such
an unsequenced side effect occurs in any of the orderings.
Hier, im Vergleich
if(string[i+j] != pattern[j++])
Sie sowohl den Wert von j
mit pattern [j++]
erhöht wird, und mit dem Wert von j
in string [i + j]
. Der Nebeneffekt von j++
ist nicht in Bezug auf die Wertberechnung i + j
sequenziert. Das ist klassisches undefiniertes Verhalten.
Wo wird 'i' deklariert/initialisiert? –
@MartinJames Das ist irrelevant. – nos
Sie könnten [diese Frage] (http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points?rq=1) eine interessante Lektüre finden. – WhozCraig