加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

这是C/C++中未定义的行为吗?

发布时间:2020-12-16 10:35:28 所属栏目:百科 来源:网络整理
导读:参见英文答案 3 plus symbols between two variables (like a+++b) in C ????????????????????????????????????3个 int x = 2;int y = 5;int z = x +++ y;printf("%d",z); VC和GCC都给出7作为输出.我的困惑在于,它可能是x y或x y.这个定义了吗? 解决方法 根
参见英文答案 > 3 plus symbols between two variables (like a+++b) in C ????????????????????????????????????3个

int x = 2;
int y = 5;

int z = x +++ y;

printf("%d",z);

VC和GCC都给出7作为输出.我的困惑在于,它可能是x y或x y.这个定义了吗?

解决方法

根据最大munch规则编译器总是将x y解释为x y,因此行为定义良好.

C11:6.4词汇元素:

P(4)

If the input stream has been parsed into preprocessing tokens up to a given character,the next preprocessing token is the longest sequence of characters that could constitute a preprocessing token.[…]

P(6)

EXAMPLE 2 The program fragment x+++++y is parsed as x ++ ++ + y,which violates a constraint on increment operators,even though the parse x ++ + ++ y might yield a correct expression.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读