【C开发】无限循环 while(1) 和 for(; ;)

无限循环有两种常用的方法:

while(1) 和 for(; ; ) 。

两种方法的效果一样,相比之下,哪种更好些?

编译后代码对比:

1、while( 1 );

00401028 mov eax,1
0040102D test eax,eax
0040102F je main+23h (00401033)
00401031 jmp main+18h (00401028)

 2、for( ; ; );

00401033 jmp main+23h (00401033)

对比发现,for(; ;)指令少,不占用寄存器,而且没有判断、跳转,比while( 1 )要好一些。

 

PS:在VC6.0中,设断点调试,菜单View -> Debug Windows ->  Disassembly即可查看编译后代码。

 

 

 

posted @ 2013-01-24 21:39  断肠人在刷牙牙  阅读(803)  评论(2编辑  收藏  举报