a [i] = a [j] ......危险吗? [英] a[i] = a[j]... Dangerous?

查看:80
本文介绍了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

推荐答案

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

我有点不清楚是否有声明如''a [i] = a [j];''导致

未定义的行为或其他一些异常。
I''m a bit unclear whether a statement such as ''a[i] = a[j];'' causes
undefined behavior or some other abnormalities.



它没有。


-

pete

It doesn''t.

--
pete


文章< 20 **************** @ gmail.com>,

Kaz Kylheku< kk ******@gmail.com写道:
In article <20****************@gmail.com>,
Kaz Kylheku <kk******@gmail.comwrote:

>注意a [i] = a [i]是明确定义的,从中可以得出即使i == j,a [i] = a [j]
也很明确。
>Note that a[i] = a[i] is well-defined, from which it follows that a[i] = a[j]
is well defined even if i == j.



我现在似乎不记得了...如果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


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

>

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

未定义的行为或其他一些异常情况。一个声明如

''a [i] = a [i ++];''肯定会导致问题,因为

双重使用和副作用''我''。但在前一种情况下,

是否会使用数组a引起问题?或者首先评估分配的权利

操作数(''[j]'')然后将
安全地分配给右操作数(''a [一世]'')?
>
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]'')?



是的。但是,在[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] ......危险吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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