本文介绍了a [i] = a [j] ......危险吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点不清楚诸如'a [i] = a [j];''之类的陈述是否导致

未定义的行为或其他一些异常。诸如

''a [i] = a [i ++];''之类的陈述肯定会导致问题,因为使用双$

和''我的副作用''。但在前一种情况下,使用数组a的双倍会导致问题吗?或者首先评估正确的操作数

(''[j]''),然后安全地分配

到右操作数(''a [ i]'')?


谢谢

I''m a bit unclear whether a statement such as ''a[i] = a[j];'' causes
undefined behavior or some other abnormalities. A statement such as
''a[i] = a[i++];'' would definitely cause problems because of the double
use and side effect of ''i''. But in the former case, will the double
use of the array ''a'' cause problems? Or will the right operand
(''a[j]'') of the assignment be evaluated first and then safely assigned
to the right operand (''a[i]'')?

Thanks

推荐答案



它没有。


-

pete

It doesn''t.

--
pete




我现在似乎不记得了...如果a是一个

volatile sig_atomic_t的数组,而且声明a [i] = a [i];正在执行的是
,有一个信号处理程序被触发,它会改变

a [i],什么是明确定义的?结果?

-

世界上每个人的百分之百都是傻瓜而且我们其他人都有被污染的危险" - Walter Matthau

I don''t seem to recall at the moment... if a is an array of
volatile sig_atomic_t and while the statement a[i] = a[i]; is
being executed, there is a signal handler fired which changes
a[i], what is the "well defined" result?
--
"Eightly percent of the people in the world are fools and the
rest of us are in danger of contamination." -- Walter Matthau




是的。但是,在[j]的值

之前计算出[i] _may_的指针。你的表达是安全的。


-

[邮件]:Chuck F(cinefalconer at maineline dot net)

[page ]:< http://cbfalconer.home.att.net>

尝试下载部分。

Yes. However a pointer to a[i] _may_ be computed before the value
of a[j] is derived. Your expression is safe.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


这篇关于a [i] = a [j] ......危险吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:26