while(true)与for(;;)的区别

//debug版本
#include<iostream>
using namespace std;
int main()
{
    //for (;;);
    /*
        00C152BE  jmp         main + 1Eh (0C152BEh)//直接跳转到循环,只有一条语句
    */
    int i;
    while (true);
    /*
        012C52BE  mov         eax, 1
        012C52C3  test        eax, eax
        012C52C5  je          main + 29h (012C52C9h)
        012C52C7  jmp         main + 1Eh (012C52BEh)
    */
}
/*
    总结:
        1. for(;;)指令少,不占用寄存器,
        2. while(true)要占用寄存器,指令多一些
    //在release版本下,都是一条指令
    //优化等级Od(不优化)O1(优化体积最小),O2(速度最快),Ox(完全优化)
*/
////debug版本
//#include<iostream>
//using namespace std;
//int main()
//{
//  int i;
//  //for (;;);
//  //013812A0  jmp         main(013812A0h)
//  while (true);
//  //013B12A0  jmp         main (013B12A0h)  
//}
///*
//  release版本下
//  都是一条指令
//*/
posted @ 2017-08-14 17:18  乐天的java  阅读(70)  评论(0)    收藏  举报