是a = 0; b =(a ++,a + 1);未定义行为(UB)? [英] Is a = 0; b = (a++, a + 1) ; undefined behavior (UB)?
本文介绍了是a = 0; b =(a ++,a + 1);未定义行为(UB)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看简单示例:
int a = 0;
int b = (a ++ , a + 1); // result of b is UB or well defined ? (c++03).
在c ++ 11 / c ++ 14中更改了
This was changed in c++11/c++14 ?
推荐答案
结果是很好定义的,自从C ++ 98。逗号运算符在 a
的写入和第二次读取之间引入序列点(或在后面的C ++中的先后顺序关系),而我不请参阅任何其他未定义行为的潜在原因。
The result is well defined and has been since C++98. The comma operator introduces a sequence point (or a "sequenced before" relationship in later C++s) between the the write and the second read of a
and I don't see any other potential reasons for undefined behavior.
这篇关于是a = 0; b =(a ++,a + 1);未定义行为(UB)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文