易变的表达 [英] volatile expression

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

问题描述

鉴于此代码:


extern volatile unsigned char v;


int main(无效)

{

v;


返回0;

}


我的理解是那个v;是一个表达式声明,

应该被评估。作为副作用的无效表达,但是

评价需要操作员。是否将声明更改为


v + 0;





(v);


改变了吗?


我有一些编译器和一些不能访问的编译器

" v" ;使用上面的代码。


-

John W. Temples,III

Given this code:

extern volatile unsigned char v;

int main(void)
{
v;

return 0;
}

My understanding is that that "v;" is an expression statement which
should be "evaluated" as a void expression for side effects, but that
"evaluation" requires an operator. Does changing the statement to

v + 0;

or

(v);

change this?

I have some compilers which do and some compilers which do not access
"v" with the above code.

--
John W. Temples, III

推荐答案

John Temples< us **** @ xargs-spam.com>潦草地写道:
John Temples <us****@xargs-spam.com> scribbled the following:
给定此代码:
extern volatile unsigned char v;
int main(无效)
{
v;
返回0;
}
我的理解是那个v;是一个表达陈述,应该评估。作为副作用的无效表达,但是评估是指需要操作员。将语句更改为
v + 0;

(v);
更改此内容?
我有一些编译器和一些不能访问的编译器
v使用上面的代码。
Given this code: extern volatile unsigned char v; int main(void)
{
v; return 0;
} My understanding is that that "v;" is an expression statement which
should be "evaluated" as a void expression for side effects, but that
"evaluation" requires an operator. Does changing the statement to v + 0; or (v); change this? I have some compilers which do and some compilers which do not access
"v" with the above code.




" v;"非常像一个表达式,就像v + 0;和(v);是。如果

编译器没有在

表达式v;中评估volatile变量v的值,那么它就违反了标准。 C标准

明确规定在

表达式中提及volatile变量必须导致对该变量值的评估。

非易失性变量可以在这样的表达式中进行优化,但是b
volatile变量不能。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi)-------------芬兰-------- \

\ - http://www.helsinki.fi/~palaste --- ------------------规则! -------- /

更强,没有。黑暗面更加诱人,狡猾,笨拙。

- Mika P. Nieminen



"v;" is very much an expression, just like "v + 0;" and "(v);" are. If a
compiler does not evaluate the value of the volatile variable v in the
expression "v;", then it is breaking the standard. The C standard
expressly dictates that any mention of a volatile variable in an
expression must result in evaluation of that variable''s value.
Non-volatile variables can be optimised away in such expressions but
volatile variables cannot.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Stronger, no. More seductive, cunning, crunchier the Dark Side is."
- Mika P. Nieminen


文章< news:6a ** ******************@iswest.net>

John Temples< us **** @ xargs-spam.com>写道:

[trimmed]
In article <news:6a********************@iswest.net>
John Temples <us****@xargs-spam.com> wrote:
[trimmed]
extern volatile unsigned char v;
v;
我的理解是那个v;是一个表达陈述,应该评估。作为副作用的无效表达...
我有一些编译器和一些不能访问的编译器
v使用上面的代码。
extern volatile unsigned char v;
v;
My understanding is that that "v;" is an expression statement which
should be "evaluated" as a void expression for side effects ...
I have some compilers which do and some compilers which do not access
"v" with the above code.




这是C99草案的引用(措辞基本上与原来的1989 ANSI C标准的原因不一致):


[#6]具有volatile限定类型的对象可能是以实现未知的方式修改或者有其他

未知的副作用。因此,任何涉及

这样一个对象的表达式都应严格按照抽象机器的

规则进行评估,如5.1.2.3所述。

此外,在每个序列点,对象中最后存储的值

应与

摘要机器规定的值一致,除非由未知因素修改

之前提到过。对于具有volatile限定类型的

对象的访问构成是实现 -

定义。


最后一句话是关键点:实现的文档

必须说明什么使得某些内容成为访问权限。一个挥发性合格的类型

对象,如v。


因此,打开编译器附带的文档,参见

是否说v;构成一个访问,你会发现

是否编译器应该生成一个。


(实际上,给定选项,我个人拒绝 - 或者

最不严重的降级 - 任何编译器都不会尝试在这里加载vb加载v,无论实现的内容如何/>
文件。当然,必须经常用令人讨厌的编译器对所需的编译器功能进行权衡。但如果文件

说v; ;是一个访问,并且编译器不生成任何代码,至少有一个明显的错误报告理由。

-

In-Real-Life:风河系统Chris Torek

美国犹他州盐湖城(40°39.22''N,111°50.29''W)+1 801 277 2603

电子邮件:忘了它 http://web.torek .net / torek / index.html

阅读由于垃圾邮件发送者,电子邮件就像在垃圾中搜索食物一样。



Here is a quote from a C99 draft (wording essentially unchanged from
the original 1989 ANSI C standard):

[#6] An object that has volatile-qualified type may be
modified in ways unknown to the implementation or have other
unknown side effects. Therefore any expression referring to
such an object shall be evaluated strictly according to the
rules of the abstract machine, as described in 5.1.2.3.
Furthermore, at every sequence point the value last stored
in the object shall agree with that prescribed by the
abstract machine, except as modified by the unknown factors
mentioned previously.99 What constitutes an access to an
object that has volatile-qualified type is implementation-
defined.

The last sentence is the key here: the implementation''s documentation
must state what make something an "access" to a volatile-qualified-type
object like "v".

So, open up the documentation that came with your compiler, see
whether it says "v;" constitutes an "access", and you will find
out whether the compiler should have generated one.

(In practice, given the option, I personally would reject -- or at
least seriously downgrade -- any compiler that does not attempt to
"load v" here, regardless of the contents of the implementation
document. Of course, one must often trade off obnoxious compiler
behavior against required compiler features. But if the document
says "v;" is an access, and the compiler generates no code, you have
obvious grounds for a bug report, at least.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22''N, 111°50.29''W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.


在文章< ch ********** @ oravannahka.helsinki.fi> ;,

Joona I Palaste< pa ***** @ cc.helsinki.fi>写道:
In article <ch**********@oravannahka.helsinki.fi>,
Joona I Palaste <pa*****@cc.helsinki.fi> wrote:
John Temples< us **** @ xargs-spam.com>潦草地写道:
John Temples <us****@xargs-spam.com> scribbled the following:
给定此代码:
extern volatile unsigned char v;
extern volatile unsigned char v;


int main(void )
{
v;
int main(void)
{
v;


return 0;
}
return 0;
}



[snippage]

" v;"非常像一个表达式,就像v + 0;和(v);是。如果
编译器没有在
表达式v;中评估volatile变量v的值,那么它就违反了标准。


这不是很强吗?

C标准明确规定任何提及变量的变量/>表达式必须导致评估该变量的值。


[snippage]
"v;" is very much an expression, just like "v + 0;" and "(v);" are. If a
compiler does not evaluate the value of the volatile variable v in the
expression "v;", then it is breaking the standard.
Isn''t that a little bit strong?
The C standard
expressly dictates that any mention of a volatile variable in an
expression must result in evaluation of that variable''s value.




我认为它是*访问*一个易失性对象,其中究竟是什么

构成一个访问是实现定义的。

因此,如果实现者由于某种原因选择不定义这个

作为v的访问权限,那么不为它生成代码是可以接受的。

(是否可以信任这样的编译器来获得更多的b / b复杂表达式中的易失性访问右是当然是另一回事。)

dave


-

Dave Vandervies dj ****** @ csclub.uwaterloo.ca

实用解决方案#1:杀死有问题的程序员。这也是最令人满意的解决方案,因为它确保了

问题不再发生。 --Ben Pfaff in comp.lang.c



I thought it was any *access to* a volatile object, where exactly what
constitutes an access is implementation-defined.
So if the implementor, for some reason, chooses to not define this
as an access to v, then it''s acceptable to not generate code for it.
(Whether such a compiler can be trusted to get volatile accesses in more
complex expressions "right" is of course a different matter.)
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Practical Solution #1: Kill the programmer in question. This is
also the most satisfying solution, because it ensures that the
problem will not recur. --Ben Pfaff in comp.lang.c


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

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