强制执行指令? [英] Enforce instruction ordering?
问题描述
嗨!
在C中是否有任何方法可以保证指令是按照与程序中写入的顺序执行的
?
例如,说我有以下内容:
instruction1;
instruction2;
instruction3;
是否可以调用某些函数/命令来确保按此顺序执行
指令?
Hi!
Is there any way in C that one can guarantee that instructions are
executed in the same order as they are written in the program?
For example, say I have the following:
instruction1;
instruction2;
instruction3;
Is it possible to call some function/command to ensure that the
instructions are executed in this order?
推荐答案
dspfun说:
dspfun said:
嗨!
在C中是否有任何方法可以保证说明是按照程序中的相同顺序执行的?$ / b
例如,假设我有以下内容:
instruction1;
instruction2;
instruction3;
>
是否可以调用某些函数/命令以确保按此顺序执行
指令?
Hi!
Is there any way in C that one can guarantee that instructions are
executed in the same order as they are written in the program?
For example, say I have the following:
instruction1;
instruction2;
instruction3;
Is it possible to call some function/command to ensure that the
instructions are executed in this order?
你不需要。分号标记序列点,正确订购
。
-
Richard Heathfield >
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上述域名中, - www。
You don''t need to. The semicolons mark "sequence points", which impose
the correct ordering.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
C中有什么方法可以保证说明是
Is there any way in C that one can guarantee that instructions are
的执行顺序与在程序中编写的顺序相同?
executed in the same order as they are written in the program?
例如,假设我有以下内容:
For example, say I have the following:
instruction1 ;
instruction2;
instruction3;
instruction1;
instruction2;
instruction3;
是否可以调用某些函数/命令以确保按此顺序执行
指令?
Is it possible to call some function/command to ensure that the
instructions are executed in this order?
你不需要。分号标记序列点,它将
正确排序。
You don''t need to. The semicolons mark "sequence points", which impose
the correct ordering.
好的,太棒了!谢谢你的回答!
Ok, great! Thanks for clear answer!
Richard Heathfield写道:
Richard Heathfield wrote:
dspfun说:
dspfun said:
>嗨!
在C中是否有任何方法可以保证指令以与它们相同的顺序执行写在程序中?
例如,说我有以下内容:
指令1;
指令2;
指令3;
指令?
>Hi!
Is there any way in C that one can guarantee that instructions are
executed in the same order as they are written in the program?
For example, say I have the following:
instruction1;
instruction2;
instruction3;
Is it possible to call some function/command to ensure that the
instructions are executed in this order?
你不需要。分号标记序列点,它将正确的排序强加给b
。
You don''t need to. The semicolons mark "sequence points", which impose
the correct ordering.
嗯,是的,不是。确实有序列点,
但它们只存在于抽象机器中。当抽象的
机器达到一个序列点时,真机的状态
必须与摘要一致 - 但仅限于
符合C程序可以检测到协议(或缺少协议)。
例如,如果三行是
x = sin(a)* cos(b)+ cos(a)* sin(b);
y = cos(a)* cos(b) - sin(a)* sin(b);
z = atan2(y,x);
....一个足够聪明的编译器可能只生成五个
而不是九个函数调用,相当明显改变
明显的操作顺序。当
编译器执行此操作时,我们通常喜欢它,并称赞它为优化。
如果符合程序,编译器可以执行此类操作
不能告诉他们已经完成了,但对于不合格的程序,这可能仍然会造成问题
。如果dspfun试图满足
一些超出C本身的限制(I / O寄存器?内存障碍?)
他需要依赖于-c-b - 自己的框架。
-
Eric Sosman
es ***** @ acm-dot-org.inva 盖子
这篇关于强制执行指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!