简单的解析问题
可能的重复:
谁能解释一下这些未定义的行为(i = i++ + ++i , i = i++ 等...)
未定义的行为和序列点(C++ 常见问题解答条目)
在C和C++中如何表达x++++y
已解析?作为 x++ ++ +y 或作为 x++ + ++y ?
Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
Undefined Behavior and Sequence Points (C++ FAQ entry)
In C and C++ how is the expression x+++++y
parsed? As x++ ++ +y
or as x++ + ++y
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
x+++++y
被解析为x ++ ++ + y
而不是x ++ + ++ y
。根据 Maximal Munch 原则,“分词器应该不断从源文件中读取字符,直到添加多一个字符会导致当前标记不再有意义”x++ ++ +y
不应编译(在 C 和 C++ 中),因为后递增运算符++ 需要一个
lvalue
作为参数并返回一个rvalue
。x+++++y
is parsed asx ++ ++ + y
and not asx ++ + ++ y
. According to Maximal Munch principle "the tokenizer should keep reading characters from the source file until adding one more character causes the current token to stop making sense"x++ ++ +y
should not compile(In C and C++) because the post-increment operator++
requires anlvalue
as an argument and returns anrvalue
.