无限循环有两种常用的方法:
while(1) 和 for(; ; ) 。
两种方法的效果一样,相比之下,哪种更好些?
编译后代码对比:
1、while( 1 );
00401028 mov eax,10040102D test eax,eax0040102F je main+23h (00401033)00401031
jmp main+18h (00401028)
2、for( ; ; );
00401033 jmp main+23h (00401033)
对比发现,for(; ;)指令少,不占用寄存器,而且没有判断、跳转,比while( 1 )要好一些。
while(1) 和 for(; ; ) 。
两种方法的效果一样,相比之下,哪种更好些?
编译后代码对比:
1、while( 1 );
00401028 mov eax,10040102D test eax,eax0040102F je main+23h (00401033)00401031
jmp main+18h (00401028)
2、for( ; ; );
00401033 jmp main+23h (00401033)
对比发现,for(; ;)指令少,不占用寄存器,而且没有判断、跳转,比while( 1 )要好一些。
只是直接转过来,未考证。。。