Is quot;for(;;)quot; faster than quot;while (true)quot;? If not, why do people use it?(是“for(;;)比“while(真)快?如果不是,人们为什么要使用它?)
问题描述
for (;;) {
//Something to be done repeatedly
}
我见过这种东西用得很多,但我觉得它很奇怪......说 while(true) 或类似的东西不是更清楚吗?
I have seen this sort of thing used a lot, but I think it is rather strange...
Wouldn't it be much clearer to say while(true), or something along those lines?
我猜(这是许多程序员求助于神秘代码的原因)这会快一点点?
I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this is a tiny margin faster?
为什么,它真的值得吗?如果是这样,为什么不这样定义:
Why, and is it really worth it? If so, why not just define it this way:
#define while(true) for(;;)
另见:哪个更快:while(1) 还是 while(2)?
推荐答案
- 并没有更快.
- 如果您真的很在意,请使用适用于您平台的汇编器输出进行编译,然后看看.
- 没关系.这从来都不重要.随心所欲地编写无限循环.
这篇关于是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“for(;;)"比“while(真)"快?如果不是,人们为什么要使用它?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
