“表达式可以产生值......” [英] "An expression can result in a value..."

查看:68
本文介绍了“表达式可以产生值......”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力提高我对C ++的正式理解。这项工作的一个重要部分

包括澄清我对所用词汇的理解

来描述语言。


这是来自C ++标准:


" [注意:第5条定义了

表达式的语法,评估顺序和含义。表达式是运算符和操作数的序列,

指定计算。表达式可能会产生一个值,而
会导致副作用。 ...]


...指定计算的运算符和操作数序列......

这对我意味着表达式可以执行。我故意将

避免使用评估一词。因为它有内涵我不是

肯定适用于所有表达式。尽管如此,计算的概念

对我来说意味着当控制流到达编译程序中的点时,某种预定的状态变化发生在


对应于源代码中出现的/ expression /。所以我的

第一个问题是:


我们如何制定计算的定义?在上面引用的摘录中传达

意图的含义?


我的第二个问题涉及表达式可能导致的确切含义

in a value ...。 ''产生价值'的概念表明,在执行

执行的那一刻(评估可能适用的那一刻),有一些存储地点保留了所述价值。这里的表达式是

完成。我注意到标准没有具体说明

表达式可以/返回/一个值。在我看来,返回一个非void类型的函数的结果值将是返回的值。

但是传递给非const参数的值又如何呢?通过引用?

这些是否被认为是副作用,结果值,或两者兼而有之?

在C ++用语中,是由`int x产生的值, y; /*...*/ x + y;''

被视为返回值?有没有一个实例,其中

表达式的结果值无法正确调用

其返回值?

-

NOUN:1。遗嘱遗留给他人的金钱或财产。 2.从祖先或前任或过去那里下来的东西:b
宗教自由的遗产。 ETYMOLOGY:MidE legacie,副手办公室,来自OF,来自ML legatia的
,来自L legare,以及deute,遗赠。 www.bartleby.com/61/

I''m trying to improve my formal understanding of C++. One significant part
of that effort involves clarifying my understanding of the vocabulary used
to describe the language.

This is from the C++ Standard:

"[Note: Clause 5 defines the syntax, order of evaluation, and meaning of
expressions. An expression is a sequence of operators and operands that
specifies a computation. An expression can result in a value and
can cause side effects. ...]"

"...sequence of operators and operands that specifies a computation...".
That means to me that an expression can be "executed". I am purposely
avoiding the term "evaluate" because that has connotations which I am not
sure apply to all expressions. Nonetheless, the notion of a computation
signifies to me that some kind of predetermined state change takes place at
the time the flow of control reaches the point in the compiled program
corresponding to the /expression/ appearing in the source code. So my
first question is:

How might we formulate a definition of "computation" which communicates the
intended meaning in the above quoted excerpt?

My second question involves the exact meaning of "An expression can result
in a value...". The concept of ''resulting in a value'' suggests there is
some storage location holding said value at the instant at which the
execution ("evaluation" probably applies here) of the expression is
complete. I note that the Standard does not specifically state that an
expression can /return/ a value. It seems to me that the resulting value
of a function returning a type other than void will be the value returned.
But what about values assigned to non-const parameters passed by reference?
Are these to be considered side effects, resulting values, or both?

In C++ parlance, is the value resulting from `int x, y;/*...*/ x + y;''
considered a "return value"? Is there ever an instance in which
the ''resulting value'' of an expression cannot properly be called
its ''return value''?
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/

推荐答案



Steven T. Hatton写道:

Steven T. Hatton wrote:

我正在努力改善我的正式理解C ++。这项工作的一个重要部分

包括澄清我对所用词汇的理解

来描述语言。


这是来自C ++标准:


" [注意:第5条定义了

表达式的语法,评估顺序和含义。表达式是运算符和操作数的序列,

指定计算。表达式可能会产生一个值,而
会导致副作用。 ...]


...指定计算的运算符和操作数序列......

这对我意味着表达式可以执行。我故意将

避免使用评估一词。因为它有内涵我不是

肯定适用于所有表达式。尽管如此,计算的概念

对我来说意味着当控制流到达编译程序中的点时,某种预定的状态变化发生在


对应于源代码中出现的/ expression /。所以我的

第一个问题是:


我们如何制定计算的定义?在上面引用的摘录中传达

意图的含义?


我的第二个问题涉及表达式可能导致的确切含义

in a value ...。 ''产生价值'的概念表明,在执行

执行的那一刻(评估可能适用的那一刻),有一些存储地点保留了所述价值。这里的表达式是

完成。我注意到标准没有具体说明

表达式可以/返回/一个值。在我看来,返回一个非void类型的函数的结果值将是返回的值。

但是传递给非const参数的值又如何呢?通过引用?

这些是否被认为是副作用,结果值,或两者兼而有之?

在C ++用语中,是由`int x产生的值, y; /*...*/ x + y;''

被视为返回值?是否存在一个实例,其中表达式的结果值无法正确调用

其返回值?
I''m trying to improve my formal understanding of C++. One significant part
of that effort involves clarifying my understanding of the vocabulary used
to describe the language.

This is from the C++ Standard:

"[Note: Clause 5 defines the syntax, order of evaluation, and meaning of
expressions. An expression is a sequence of operators and operands that
specifies a computation. An expression can result in a value and
can cause side effects. ...]"

"...sequence of operators and operands that specifies a computation...".
That means to me that an expression can be "executed". I am purposely
avoiding the term "evaluate" because that has connotations which I am not
sure apply to all expressions. Nonetheless, the notion of a computation
signifies to me that some kind of predetermined state change takes place at
the time the flow of control reaches the point in the compiled program
corresponding to the /expression/ appearing in the source code. So my
first question is:

How might we formulate a definition of "computation" which communicates the
intended meaning in the above quoted excerpt?

My second question involves the exact meaning of "An expression can result
in a value...". The concept of ''resulting in a value'' suggests there is
some storage location holding said value at the instant at which the
execution ("evaluation" probably applies here) of the expression is
complete. I note that the Standard does not specifically state that an
expression can /return/ a value. It seems to me that the resulting value
of a function returning a type other than void will be the value returned.
But what about values assigned to non-const parameters passed by reference?
Are these to be considered side effects, resulting values, or both?

In C++ parlance, is the value resulting from `int x, y;/*...*/ x + y;''
considered a "return value"? Is there ever an instance in which
the ''resulting value'' of an expression cannot properly be called
its ''return value''?



我不确定我的理解比你好,所以

我在说什么可能对你来说很明显。 (或者可能是错误的......)


但我的理解是,在你想到的东西之间没有根本的区别

返回值和标准

调用产生的值。 5 + 6;不会返回一个值,因为它没有* b $ b不会*返回*任何东西。 "返回"是一个关于控制流的声明。

(可能有一个值附加到它,就像在返回

int的函数中一样,但重点是它至少有一个重要的部分是

控制流。)

I''m not sure that I''m better off in my understanding than you, so what
I''m saying might be blatently obvious to you. (Or possibly wrong...)

But my understanding is that there''s not a fundamental difference
between what you''re thinking of a return value and what the standard
calls resulting in a value. 5+6; doesn''t return a value, because it
doesn''t *return* anything. "Return" is a statement about control flow.
(There might be a value attached to it, as in a function returning an
int, but the point is that it at least has a substantial part that is
control flow.)


但是,通过引用传递给非const参数的值又如何呢?

这些是否被视为副作用,结果值或两者兼而有之?
But what about values assigned to non-const parameters passed by reference?
Are these to be considered side effects, resulting values, or both?



你是否在标记的行上说:


int foo(xnt& x){x = 1;返回2; }

int bar(){

int a;

foo(a)+ 5; //< =这里

}


a值的变化被视为副作用,产生价值,

或者两者兼而有?


如果是这样,那肯定只是副作用。结果值

''foo(a)''应为2,然后是整个表达式语句,7。


Evan

Are you saying that on the marked line:

int foo(xnt& x) { x=1; return 2; }
int bar() {
int a;
foo(a) + 5; // <= here
}

the change in value of a is considered a side effect, resulting value,
or both?

If so, that''s definitely just a side effect. The resulting value of
''foo(a)'' should be 2, and then of the whole expression statement, 7.

Evan


Steven T. Hatton< ch ******** @ germania.supwrote:
Steven T. Hatton <ch********@germania.supwrote:

>在C ++的说法中,是由int x,y; /*...*/ x + y产生的值;''
被认为是返回值?是否存在一个实例,其中表达式的结果值无法被正确地称为返回值?
>In C++ parlance, is the value resulting from `int x, y;/*...*/ x + y;''
considered a "return value"? Is there ever an instance in which
the ''resulting value'' of an expression cannot properly be called
its ''return value''?



我只使用返回值对于函数返回的值。


其他人可能会使用不同的短语。


Steve

I only use "return value" for the value returned by a function.

Others may use the phrase differently.

Steve


Evan写道:
Evan wrote:

>

Steven T. Hatton写道:
>
Steven T. Hatton wrote:

>我正在努力提高我对C ++的正式理解。这项工作的一个重要部分是澄清我对用于描述语言的词汇的理解。

这是来自C ++标准:

[注意:第5条定义了语法,评估顺序和
表达的含义。表达式是指定计算的运算符和操作数序列。表达式可能会导致值,并且
可能会导致副作用。 ...]

...指定计算的运算符和操作数的序列......
这对我来说意味着表达式可以被执行 ;。我故意避免使用评估这个术语。因为这具有我不确定适用于所有表达的内涵。尽管如此,计算的概念对我来说意味着在控制流程达到编译程序中对应于/表达式的点时会发生某种预定的状态变化。 /出现在源代码中。所以我的第一个问题是:

我们如何制定计算的定义?在上面引用的摘录中传达了意图的含义?

我的第二个问题涉及表达式可以结果
的确切含义。 " ;. 导致价值的概念表明,在表达式的执行(评估可能适用于此处)的时刻,某些存储位置保持所述值。 />完成。我注意到标准没有具体说明
表达式可以/返回/一个值。在我看来,返回除void之外的类型的函数的结果值将是返回的值
。但是通过引用传递给非const参数的值呢?这些是否被视为副作用,结果值,或两者兼而有?

用C ++的说法,是由'int x,y; /*...*/ x +产生的值y;''
被视为返回值?是否存在一个实例,其中表达式的结果值无法被正确地称为返回值?
>I''m trying to improve my formal understanding of C++. One significant
part of that effort involves clarifying my understanding of the
vocabulary used to describe the language.

This is from the C++ Standard:

"[Note: Clause 5 defines the syntax, order of evaluation, and meaning of
expressions. An expression is a sequence of operators and operands that
specifies a computation. An expression can result in a value and
can cause side effects. ...]"

"...sequence of operators and operands that specifies a computation...".
That means to me that an expression can be "executed". I am purposely
avoiding the term "evaluate" because that has connotations which I am not
sure apply to all expressions. Nonetheless, the notion of a computation
signifies to me that some kind of predetermined state change takes place
at the time the flow of control reaches the point in the compiled program
corresponding to the /expression/ appearing in the source code. So my
first question is:

How might we formulate a definition of "computation" which communicates
the intended meaning in the above quoted excerpt?

My second question involves the exact meaning of "An expression can
result
in a value...". The concept of ''resulting in a value'' suggests there is
some storage location holding said value at the instant at which the
execution ("evaluation" probably applies here) of the expression is
complete. I note that the Standard does not specifically state that an
expression can /return/ a value. It seems to me that the resulting value
of a function returning a type other than void will be the value
returned. But what about values assigned to non-const parameters passed
by reference? Are these to be considered side effects, resulting values,
or both?

In C++ parlance, is the value resulting from `int x, y;/*...*/ x + y;''
considered a "return value"? Is there ever an instance in which
the ''resulting value'' of an expression cannot properly be called
its ''return value''?



我不确定我的理解比你好,所以

我在说什么可能对你来说很明显。 (或者可能是错误的......)


但我的理解是,在你想到的东西之间没有根本的区别

返回值和标准

调用产生的值。 5 + 6;不会返回一个值,因为它没有* b $ b不会*返回*任何东西。 "返回"是一个关于控制流的声明。

(可能有一个值附加到它,就像在返回

int的函数中一样,但重点是它至少有一个重要的部分是

控制流量。)


I''m not sure that I''m better off in my understanding than you, so what
I''m saying might be blatently obvious to you. (Or possibly wrong...)

But my understanding is that there''s not a fundamental difference
between what you''re thinking of a return value and what the standard
calls resulting in a value. 5+6; doesn''t return a value, because it
doesn''t *return* anything. "Return" is a statement about control flow.
(There might be a value attached to it, as in a function returning an
int, but the point is that it at least has a substantial part that is
control flow.)



自从我详细了解了激活

堆栈工作,但IIRC,编译

表达式产生的指令与任何自动变量一起放在堆栈上。

变量从正在执行的代码外部可见的必须是由他们的地址引用的
。任何值返回通过函数必须将

放在存储器中,可以在函数返回后访问。在

这个上下文中返回表示指令指针已到达函数的最后一个

指令,然后假定后续

指令的地址。


所以,是的,

返回概念涉及控制流程的重要组成部分。似乎合理的结论是,在执行产生值的函数之前,返回值(如果有的话)将被放置到的地址

范围内必须是




我不知道用于初始化指向

函数的函数的地址如何与返回值的存储位置相关。 br />

我确实相信返回的概念。适用于算术

表达式,如int x,y; X + Y;我不确定它与用户编写的函数调用发生的分支和返回有什么不同。

要记住C ++的一件事是有一个返回

引用的概念,这让我对得出任何关于

的结论持谨慎态度,这意味着有一个返回值。我也不确定存储的执行时间特性与用于返回值的
位置和用于存储位置之间存在什么差异?

一个

可变参数。


我倾向于将''返回值''和'结果值'视为

同义词,但这是C ++。一切皆有可能。

It''s been a long time since I went through the details of how an activation
stack works, but IIRC, the instructions resulting from compiling an
expression are put on the stack along with any automatic variables.
Variables which are visible from outside the code being executed have to be
referred to by their addresses. Any value "returned" by a function must be
placed in storage which can be accessed after the function returns. In
this context "returning" means the instruction pointer has reached the last
instruction of the function, and then assumed the address of the subsequent
instruction.

So, yes, there is a significant component of control flow involved in the
notion of "returning". It seems reasonable to conclude that the address
range into which the return value (if any) will be placed must be
established prior to execution of the function producing the value.

I''m not sure how the address of a function used to initialize a pointer to
function relates to the storage location of a return value.

I do believe the notion of "returning" is applicable to arithmetic
expressions such as int x, y; x+y; I''m not sure how it might differ from
the branch and return that takes place with a user written function call.
One thing to keep in mind with C++ is that there is a notion of returning
references which makes me cautious about jumping to any conclusions about
what it means to have a return value. I''m also not sure what, if any,
differences exist between the execution time characteristics of a storage
location used for a return value and the storage location used for a
variable parameter.

My inclination is to think of ''return value'' and ''resulting value'' as
synonymous, but this is C++. Anything is possible.


>但是,分配给
参考传递的非const参数的值怎么样?这些是否被视为副作用,结果值,或两者兼而有之?
>But what about values assigned to non-const parameters passed by
reference? Are these to be considered side effects, resulting values, or
both?



你是否在标记的行上说:


int foo(xnt& x){x = 1;返回2; }

int bar(){

int a;

foo(a)+ 5; //< =这里

}


a值的变化被视为副作用,产生价值,

或者两者兼而有?


如果是这样,那肯定只是副作用。结果值

''foo(a)''应为2,然后是整个表达式语句,7。


Are you saying that on the marked line:

int foo(xnt& x) { x=1; return 2; }
int bar() {
int a;
foo(a) + 5; // <= here
}

the change in value of a is considered a side effect, resulting value,
or both?

If so, that''s definitely just a side effect. The resulting value of
''foo(a)'' should be 2, and then of the whole expression statement, 7.



我倾向于同意,但正如我所说,这是C ++。

-

NOUN:1。遗嘱遗留给他人的金钱或财产。 2.从祖先或前任或过去那里下来的东西:b
宗教自由的遗产。 ETYMOLOGY:MidE legacie,副手办公室,来自OF,来自ML legatia的
,来自L legare,以及deute,遗赠。 www.bartleby.com/61/


这篇关于“表达式可以产生值......”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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