C ++ 11中的逗号运算符(排序) [英] Comma operator in C++11 (sequencing)

查看:113
本文介绍了C ++ 11中的逗号运算符(排序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准提到 f(a,(t = 3,t + 2),c); 根据我的理解,这将是赋值表达式,后跟第二个运算符的表达式.

The standard mentions f(a,(t=3,t+2),c); which would be an assignment-expression followed by an expression for the 2nd operator according to my understanding.

但是语法将它并列列出:

But the grammar lists it juxtaposed:

表达式:

expression:

作业表达

assignment-expression

表达式,赋值表达式

expression, assignment-expression

工作草案,编程标准 语言C ++修订版N4140(2014年11月)

Working Draft, Standard for Programming Language C ++ Revision N4140 (November 2014)

有人很高兴向我解释我在这里想念的是什么吗?

Is someone so nice as to explain to me please what it is that I'm missing here?

推荐答案

看到时

 expression:
    assignment-expression
    expression, assignment-expression

这意味着有两种表达方式.一种可能是 assignment-expression ,它是在较早的位置定义的.或者将其递归表示为 expression, assignment-expression

It mean that there are 2 possibilities for expression. One possibility that it is just assignment-expression that is defined somewhere earlier. Or it is recursively represented as expression, assignment-expression

因此,将其扩展后,您会收到一个逗号分隔的一个或多个赋值表达标记的列表.

So after extending it you receive that expression is comma separated list of one or more assignment-expression tokens.

在示例中,您提到的第二个参数是表达式(t = 3,t + 2),它由2个逗号分隔的赋值表达式组成-由于它显示为在给逗号赋予特殊含义的上下文中",必须仅出现在括号中".

In the sample you're mentioned second parameter is expression (t=3,t+2) which consists of 2 comma-separated assignment-expressions - and since it appears "In contexts where comma is given a special meaning" it has to "appear only in parentheses".

要弄清赋值表达式为什么可以采用t + 2的形式,您必须从其定义中返回并始终选择首选项

To find out why assignment-expression could take a form of t+2 you have to go back from its definitions and choose first choice always

assignment-expression
-> conditional-expression
--> logical-or-expression
---> logical-and-expression
----> inclusive-or-expression
-----> exclusive-or-expression
------> and-expression
-------> equality-expression
--------> relational-expression
---------> shift-expression
----------> additive-expression - this is what you see

这篇关于C ++ 11中的逗号运算符(排序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆