Yes. The C11 standard says 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.
Here, in the comparison
if(string[i+j] != pattern[j++])
you are both incrementing the value of j
with pattern [j++]
, and using the value of j
in string [i + j]
. The side effect of j++
is not sequenced relative to the value computation i + j
. So this is classic undefined behavior.