是init声明器的prvalue表达式 [英] Is an init-declarator a prvalue expression

查看:110
本文介绍了是init声明器的prvalue表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int c = 0;

考虑上面的代码,因此, c = 0 是一个初始化声明器,也是一个表达式,因为这些规则:

Consider the above code,thereof,c = 0 is an init-declarator and it's also an expression,Becuase of these rules:


init-declarator:

声明程序初始值设定项(opt)

init-declarator:
declarator initializer(opt)

完整表达式为:

[...]

init-declarator 或mem初始化器,包括初始化器的组成表达式

A full-expression is:
[...]
an init-declarator or a mem-initializer, including the constituent expressions of the initializer,


prvalue是一个表达式,其评估初始化了一个对象,或者有点字段,或根据出现的上下文来计算运算符的操作数的值。

A prvalue is an expression whose evaluation initializes an object or a bit-field, or computes the value of the operand of an operator, as specified by the context in which it appears.

a = 0 的求值将初始化对象 a 。因此,完整表达式 c = 0 是prvalue表达式吗?如果我误解了,请更正。

The evaluation of a = 0 will initialize object a.So, Is the full-expression c=0 a prvalue expression?If I misunderstand it,please correct me.

推荐答案


考虑上面的代码,因此,c = 0是一个init声明符,也是一个表达式

Consider the above code,thereof,c = 0 is an init-declarator and it's also an expression

这不是C ++解析的工作方式。 c = 0 本身可能就是一个表达式(如果在允许表达式的上下文中),但这不是 int c = 0的方式; 被解析。您必须遵循实际的C ++语法规则。

That's not how C++ parsing works. c = 0 by itself may be an expression (if it is within a context where expressions are allowed), but that's not how int c = 0; gets parsed. You have to follow the actual C++ grammar rules.

int c = 0; 简单声明 ,其中包含 decl-specifier -seq 和一个可选的 init-declarator-list 。后者是一个或多个 init-declarator 字词。这个语法有两个组成部分:声明符和可选的初始化器。在语法上, decl-specifier-seq int 所在的位置,声明符 c 部分,而 initializer = 0 位。

int c = 0; is a simple-declaration, containing a decl-specifier-seq and an optional init-declarator-list. The latter is a sequence of one or more init-declarator terms. And this grammar has two components: a declarator and an optional initializer. Grammatically speaking, the decl-specifier-seq is where int goes, the declarator is the c part, and the initializer is the = 0 bit.

init-declarator 的文本在某些情况下可能被解析为 expression 。但是,解析的内容由语法规则确定。而且简单声明的语法规则不允许 decl-specifier-seq 后跟 表达式 。因此,遵循它的内容即使可能也不会被解析为表达式

The text of an init-declarator is something that may in some cases be parsed as an expression. But what something is parsed as is determined by the grammar rules. And the grammar rules of simple-declaration does not allow a decl-specifier-seq followed by expression. Therefore, what follows it is not parsed as an expression even if it could be.

所以 init-declarator 不是表达式,即使文本看起来像这样。

So init-declarator is not an expression, even if the text looks like it could be.

现在,有一个完整表达 。被称为完整表达式的东西之一就是 init-declarator 语法。

Now, there is the concept of a "full-expression". One of the things that get to be called a "full-expressions" are init-declarator grammar.

令人困惑的部分是完整表达式和表达式之间的差异。 表达式一段C ++语法。全表达式不是;这是一个语言概念,其中包含许多不同的语法,但是全表达本身不是语法。

The part that's confusing you is the difference between a "full-expression" and an expression. An expression is a specific piece of C++ grammar. A full-expression is not; it's a language concept which includes a number of different pieces of grammar, but full-expression is not itself grammar.

因此,语法结构 init-declarator 是完全表达,不是 使其成为表达。语法构造 expression 的定义很明确,并且 int c = 0; 不适合该语法。 init-declarator 可能包含一个表达式(或多个表达式,具体取决于 initializer ),但这是本身不是表达式

Therefore, while the grammatical construct init-declarator is a "full-expression" that does not make it an expression. The grammar construct expression is well defined, and int c = 0; doesn't fit that grammar. The init-declarator may contain an expression (or multiple expressions, depending on the initializer), but it is not itself an expression.

只有表达式具有值类别。因此,询问不是表达式的事物的值类别不是一个有效的问题。

And only expressions have value categories. Therefore, asking about the value category of a thing which is not an expression is not a valid question.

这篇关于是init声明器的prvalue表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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