F(V [I]中,我++);是未定义还是未指定? [英] f(v[i],i++); is Undefined or Unspecified?

查看:93
本文介绍了F(V [I]中,我++);是未定义还是未指定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Bjarne Stroustrup的C ++风格与技巧常见问题解答中at:
http:// www .research.att.com / ~bs / bs_f ... aluation-order


声明:

f(v [i] ,i ++);


他说结果是未定义的,因为评估的顺序

的函数参数未定义。


但AFAIK,函数参数的评估顺序未指定

,因为C ++标准说:

" 5.2.2函数
参数评估的顺序是未指定的。


所以这不是他的错吗?


我认为它是未定义的,因为i的值被访问,并且在序列点内也被点缀为b / b
因此未定义。


Sharath AV

解决方案

av ** *****@gmail.com 写道:

在Bjarne Stroustrup的C ++风格与技巧常见问题解答中at:
http:// www .research.att.com / ~bs / bs_f ... aluation-order


声明:

f(v [i] ,i ++);


他说结果是未定义的,因为评估的顺序

的函数参数未定义。


但AFAIK,函数参数的评估顺序未指定

,因为C ++标准说:

" 5.2.2函数
参数评估的顺序是未指定的。


所以这不是他的错吗?


我认为它是未定义的,因为i的值被访问,并且在序列点内也被点缀为b / b
因此未定义。


Sharath AV



根据标准,f的值未指定,但实际上是什么意思?未定义的结果,因为我们无法保证调用f的结果是什么。我认为我们可以允许发明者在语言描述错误的影响方面有一些余地。

此外,如果每个FAQ或教科书都使用标准语言

没有解释他们几乎不可读。


干杯

吉姆。


James Bannon写道:


>>



根据标准,f的值未指定,但实际上是什么意思?未定义的结果,因为我们无法保证调用f的结果是什么。



嗯,在某种程度上,是的,但这是草率的措辞。该标准给出了

术语未定义的行为。一个特定的含义。使用该术语来表示

不同的东西简直令人困惑。所以,当你在谈论关于语言定义的
时,请使用术语未定义的行为。表示

违反计划的行为,该标准没有规定

的要求。使用术语未指定的行为表示

格式良好的程序的行为取决于实现(通常有一些明显的替代方案)。

< br>


av*******@gmail.com 写道:


InBjarne Stroustrup'的C ++ Style and Technique FAQ" at:
http:// www .research.att.com / ~bs / bs_f ... aluation-order


声明:

f(v [i] ,i ++);


他说结果是未定义的,因为评估的顺序

的函数参数未定义。


但AFAIK,函数参数的评估顺序未指定

,因为C ++标准说:

" 5.2.2函数
参数评估的顺序是未指定的。


所以这不是他的错吗?


我认为它是未定义的,因为i的值被访问,并且在序列点内也被点缀为b / b
因此未定义。


Sharath AV



他和标准都在说同样的事情。

如何同时修改和访问变量LY?多数民众赞成

不可能。

你错过了两个陈述。

他和标准所说的是没有任何限制。编译器上的
首先评估一个参数,然后另一个参数评估

任何特定序列。

未定义或未指定:同样的事情。


我也不同意你的解释。

v [i]是容器中的一个特殊元素,问题是哪一个?

答案是它没关系,未指明,未定义,谁在乎,

不保证等等。

In "Bjarne Stroustrup''s C++ Style and Technique FAQ" at:
http://www.research.att.com/~bs/bs_f...aluation-order

for the statement:
f(v[i],i++);

he says that "the result is undefined because the order of evaluation
of function arguments are undefined".

But AFAIK, the order of evaluation of function arguments is unspecified
as the C++ Standard says:
"5.2.2 Function
The order of evaluation of arguments is unspecified."

So isn''t he wrong at this?

I think it is undefined because the value of ''i'' is accessed and also
moidified within the sequence point and hence it is undefined.

Sharath A.V

解决方案

av*******@gmail.com wrote:

In "Bjarne Stroustrup''s C++ Style and Technique FAQ" at:
http://www.research.att.com/~bs/bs_f...aluation-order

for the statement:
f(v[i],i++);

he says that "the result is undefined because the order of evaluation
of function arguments are undefined".

But AFAIK, the order of evaluation of function arguments is unspecified
as the C++ Standard says:
"5.2.2 Function
The order of evaluation of arguments is unspecified."

So isn''t he wrong at this?

I think it is undefined because the value of ''i'' is accessed and also
moidified within the sequence point and hence it is undefined.

Sharath A.V

According to the standard the value of f is unspecified but what does
that mean in practice? Undefined results because we cannot guarantee
what the result of calling f will be. I think we can allow the inventor
of the language a little leeway in describing the effects of an error.
Besides if every FAQ or textbook used the language of the standard
without explanation they would be virtually unreadable.

Cheers
Jim.


James Bannon wrote:

>>

According to the standard the value of f is unspecified but what does
that mean in practice? Undefined results because we cannot guarantee
what the result of calling f will be.

Well, in a way, yes, but this is sloppy wording. The standard gives the
term "undefined behavior" a specific meaning. Using that term to mean
something different is simply confusing. So, please, when you''re talking
about the language definition, use the term "undefined behavior" to mean
behavior of an erroneous program for which the standard imposes no
requirements. Use the term "unspecified behavior" to mean behavior of a
well-formed program that depends on the implementation (usually there is
an obvious set of alternatives).



av*******@gmail.com wrote:

In "Bjarne Stroustrup''s C++ Style and Technique FAQ" at:
http://www.research.att.com/~bs/bs_f...aluation-order

for the statement:
f(v[i],i++);

he says that "the result is undefined because the order of evaluation
of function arguments are undefined".

But AFAIK, the order of evaluation of function arguments is unspecified
as the C++ Standard says:
"5.2.2 Function
The order of evaluation of arguments is unspecified."

So isn''t he wrong at this?

I think it is undefined because the value of ''i'' is accessed and also
moidified within the sequence point and hence it is undefined.

Sharath A.V

Both he and the standard are saying the same thing.
How can you modify and access a variable simultaneously? Thats
impossible.
You''ve missunderstood both statements.
What he and the standard are saying is that no restriction is imposed
on the compiler to first evaluate one argument and then the other in
any particular sequence.
Undefined or unspecified: same thing.

I disagree with your intepretation as well.
v[i] is a particular element in a container, the question is which one?
The answer is "it doesn''t matter", unspecified, undefined, "who cares",
not guarenteed, etc.


这篇关于F(V [I]中,我++);是未定义还是未指定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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