Tak. Średnia C11 mówi w § 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.
Tutaj, w porównaniu
if(string[i+j] != pattern[j++])
jesteś zarówno zwiększając wartość j
z pattern [j++]
i używając wartość j
w string [i + j]
. Efekt uboczny z j++
nie jest sekwencjonowany w stosunku do wartości obliczenia i + j
. Jest to więc klasyczne niezdefiniowane zachowanie.
Gdzie jest "i" zadeklarowane/zainicjalizowane? –
@MartinJames To nieistotne. – nos
Możesz znaleźć [to pytanie] (http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points?rq=1) interesującą lekturę. – WhozCraig