はい。 C11標準は§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.
、比較
if(string[i+j] != pattern[j++])
にあなたは両方のpattern [j++]
でj
の値をインクリメントし、string [i + j]
にj
の値を使用しています。 j++
の副作用は、値計算i + j
に対して順序付けされていません。これは古典的な未定義の動作です。
「i」はどこに宣言/初期化されていますか? –
@MartinJamesそれは無関係です。 – nos
[この質問](http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points?rq=1)に興味深い記事があります。 – WhozCraig