简体   繁体   English

后缀表达式和运算符的语法混淆

[英]Confusion with syntax for postfix expressions and operators

In the following case, 在以下情况下,

int i = 0;
int j = 42;
i = j++;

I know ++ is posfix operator, So, is j a posfix expression or should you say j++ is posfix expression ? 我知道++是posfix运算符,所以, j是posfix表达式还是应该说j++是posfix表达式?

Syntactically, both j and j++ are postfix-expressions. 从语法上讲, jj++都是后缀表达式。

See the grammar in section 5.2 of the C++ 2003 standard: 请参阅C ++ 2003标准的5.2节中的语法:

postfix-expression:
    primary-expression
    ...
    postfix-expression ++

( j is also a primary-expression; j++ is not.) j也是主要表达式; j++不是。)

The fact that a primary-expression is a kind of postfix-expression (even if it doesn't contain a postfix operator) is mostly a matter of convenience for defining the language syntax. 主表达式是一种后缀表达式(即使它不包含后缀运算符),这一事实主要是为了方便定义语言语法。 There's not much point in referring to j as a postfix-expression unless you're talking about parsing C++ (or C) source code. 除非您正在谈论解析C ++(或C)源代码,否则将j称为后缀表达式没有多大意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM