在C++ Primer第四章第六节中有讲如下程序:
while(beg!=s.end() && !isspace(*beg))
*beg=toupper(*beg++);
将产生未定义行为,编译器可能按照下面的任意一种思路处理该表达式:
*beg=toupper(*beg);
*(beg+1)=toupper(*beg);
难道不应该是,在该行内使用未加一的beg,然后在下一行中再使用加一的beg吗?为什么会产生歧义?
怪我咯2017-04-17 15:03:05
Undefined behavior occurs because beg is used on both sides of the assignment symbol.
The compiler doesn't know whether to execute the value on the left or the right first.