如何执行执行命令? [英] How to enforce execution order?

查看:122
本文介绍了如何执行执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


i有如下序列:


const char * a =" foo" ;;

char b [10];


for(i = 1; i< strlen(a); i ++)

{

b [i] = a [i];

}

b [0] = a [0];


我想,优化编译器可能会混淆这个

代码的执行顺序。我怎么能强制执行,在循环之后完成在
位置0处复制char?


我在多线程环境中工作,而Semaphores, Mutex等是不适合当前情况的



-Sacha


[见 http://www.gotw.ca/resources/clcm.htm 获取信息关于]

[comp.lang.c ++。主持。第一次海报:做到这一点! ]

Hi there,

i have a sequence like the following:

const char *a = "foo";
char b[10];

for ( i = 1; i < strlen(a); i++)
{
b[i] = a[i];
}
b[0] = a[0];

I guess, an optimizing compiler might mixup the execution order of this
code snipped. How can I enforce, that the copying of the char at
position 0 is done after the loop?

I work in a multithreaded environment, and Semaphores, Mutex etc. are
not suitable for the current situation.

-Sacha

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

推荐答案



" Sacha Sch?r" < SA ********** @ unibas.ch>在留言中写道

news:43 ********** @ news.bluewin.ch ...

"Sacha Sch?r" <sa**********@unibas.ch> wrote in message
news:43**********@news.bluewin.ch...
你好,

const char * a =" foo";
char b [10];

for(i = 1; i< strlen(a); i ++)
{
b [i] = a [i];
}
b [0] = a [0];

我想,优化编译器可能会混淆这个被剪切的代码的执行顺序。我怎么能强制执行,在位置0处复制char后是在循环之后完成?
Hi there,

i have a sequence like the following:

const char *a = "foo";
char b[10];

for ( i = 1; i < strlen(a); i++)
{
b[i] = a[i];
}
b[0] = a[0];

I guess, an optimizing compiler might mixup the execution order of this
code snipped. How can I enforce, that the copying of the char at
position 0 is done after the loop?




volatile const char * a =" foo" ;


BTW为什么你用的是C风格的字符串而不是std :: string?

-Mike



volatile const char *a = "foo";

BTW why are you using C-style strings instead of std::string?
-Mike

Sacha Sch?r写道:
Sacha Sch?r wrote:
我有如下序列:

const char * a =" foo";
char b [10];

for(i = 1; i< strlen(a); i ++)
{
b [i] = a [i];
}
b [0] = a [0];

我想,优化编译器可能会混淆这个被剪切的代码的执行顺序。如何强制执行,在循环之后复制位置0处的字符?


关闭此特定代码的优化。请参阅

您的编译器手册,了解如何操作。

我在多线程环境中工作,而Semaphores,Mutex等不适合当前没有这种情况。
i have a sequence like the following:

const char *a = "foo";
char b[10];

for ( i = 1; i < strlen(a); i++)
{
b[i] = a[i];
}
b[0] = a[0];

I guess, an optimizing compiler might mixup the execution order of this
code snipped. How can I enforce, that the copying of the char at
position 0 is done after the loop?
Turn off optimizations for this particular piece of code. Consult with
your compiler manual on how to do that.
I work in a multithreaded environment, and Semaphores, Mutex etc. are
not suitable for the current situation.




无论如何,它与您发布的新闻组无关。

没有像Semaphores这样的东西。或Mutex或Mutex。用C ++。


V



And it''s not relevant to the newsgroups you posted to, anyway. There are
no such things like "Semaphores" or "Mutex" in C++.

V


这只是猜测..内联函数怎么样?


void inline copyFirstElem(const char * a,char * b)

{

b [0] = a [0]

}


{请不要发帖。 -mod / fg}


Sacha Sch?r写道:
This is just a guess.. how about an inline function?

void inline copyFirstElem(const char *a, char *b)
{
b[0] = a[0]
}

{Please do not top post. -mod/fg}

Sacha Sch?r wrote:
你好,

我有一个如下序列:

const char * a =" foo";
char b [10];

for(i = 1; i< strlen(a); i ++)
{
b [i] = a [i];
}
b [0] = a [0];

我猜,优化编译器可能会混淆此剪切代码的执行顺序。我怎么能强制执行,在循环之后复制位置0的char?

我在多线程环境中工作,而Semaphores,Mutex等是
不适合目前的情况。
Hi there,

i have a sequence like the following:

const char *a = "foo";
char b[10];

for ( i = 1; i < strlen(a); i++)
{
b[i] = a[i];
}
b[0] = a[0];

I guess, an optimizing compiler might mixup the execution order of this
code snipped. How can I enforce, that the copying of the char at
position 0 is done after the loop?

I work in a multithreaded environment, and Semaphores, Mutex etc. are
not suitable for the current situation.




[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


这篇关于如何执行执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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