for(;;)或while(1)? [英] for(;;) or while(1)?

查看:116
本文介绍了for(;;)或while(1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




为了便携,如果我们在C中使用while(1)进行无限的

循环,是否会出现问题?如果是这样,那么我们应该使用(;;)吗?谢谢,


Rick

Hi,

For portability, can an issue arise if we use while(1) for an infinite
loop in C? If so, should we then use for(;;)? Thanks,

Rick

推荐答案

文章< 3f ***** ***@clarion.carno.net.au> ;, Rick写道:
In article <3f********@clarion.carno.net.au>, Rick wrote:


为了便于携带,如果我们使用while(1)进行安装,可能会出现问题无限循环在C?如果是这样,那么我们应该使用(;;)吗?谢谢,
Hi,

For portability, can an issue arise if we use while(1) for an infinite
loop in C? If so, should we then use for(;;)? Thanks,




有些C编译器可能会产生稍微不同的机器代码,

但是它们应该始终在功能上完全相同。选择

一个而不是另一个不会破坏程序或使其成为

不可移植。

-

Andreas K?h?ri



Some C compilers may generate slightly different machine code,
but they ought to always be functionally identical. Choosing
one instead of the other will not break a program or make it
unportable.
--
Andreas K?h?ri




" Rick" < rrquick @ NOSPAM-COM>在留言中写道

新闻:3f ******** @ clarion.carno.net.au ...

"Rick" <rrquick@nospam-com> wrote in message
news:3f********@clarion.carno.net.au...

为了便于携带,如果我们使用while(1)在C中进行无限循环,是否会出现问题?


No.

如果是,我们是否应该使用(;;)?谢谢,


当你不想暗示一个测试时,你用(;;),否则为了

目的,你使用while(1)

除了最愚蠢的

编译器之外,所有实际结果都是一样的。

Rick
Hi,

For portability, can an issue arise if we use while(1) for an infinite
loop in C?
No.
If so, should we then use for(;;)? Thanks,

You use for(;;) when you do not want to imply a test, otherwise for that
purpose, you use while(1)
The practical result will be the same for all but the very stupidest
compilers.
Rick








Rick写道:



为了便于携带,如果出现问题,可能会出现问题我们使用while(1)
在C中进行无限循环?


我的编译器会为这种代码生成一个警告,当我的警告级别高时,我会喜欢它的


如果是的话,我们应该用于(;;)吗?

Hi,

For portability, can an issue arise if we use while(1)
for an infinite loop in C?
My compiler generates a warning for that kind of code,
when I have the warning level high, where I like it.
If so, should we then use for(;;)?




我的编译器没有为该代码生成警告,

这就是我用的东西。


-

pete



My compiler doesn''t generate a warning for that code,
so that''s what I use.

--
pete


这篇关于for(;;)或while(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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