实践是检验真理的唯一标准:
VS2005, MFC dialog , Release,默认优化
// TODO: Add extra initialization here
while(1);
for(;;);
展开汇编后如下:
// TODO: Add extra initialization here
while(1);
004012A1 jmp CTestSomeCCPP_AboutDlg::OnInitDialog+0C1h (4012A1h)
--- No source file -------------------------------------------------------------
004012A3 int 3
004012A4 int 3
004012A5 int 3
004012A6 int 3
004012A7 int 3
004012A8 int 3
004012A9 int 3
004012AA int 3
004012AB int 3
004012AC int 3
004012AD int 3
004012AE int 3
004012AF int 3
--- e:\work\testsomeccpp_about\testsomeccpp_about\testsomeccpp_aboutdlg.cpp
for(;;);
=======
// TODO: Add extra initialization here
for(;;);
while(1);
展开后:
// TODO: Add extra initialization here
for(;;);
004012A1 jmp CTestSomeCCPP_AboutDlg::OnInitDialog+0C1h (4012A1h)
--- No source file -------------------------------------------------------------
004012A3 int 3
004012A4 int 3
004012A5 int 3
004012A6 int 3
004012A7 int 3
004012A8 int 3
004012A9 int 3
004012AA int 3
004012AB int 3
004012AC int 3
004012AD int 3
004012AE int 3
004012AF int 3
--- e:\work\testsomeccpp_about\testsomeccpp_about\testsomeccpp_aboutdlg.cpp
while(1);
==============
由此可见亮点:
1编译器知道死循环后,后边的就没有生成汇编代码
2 while(1);
for(;;);
在VS2005 release默认优化下是一样的;
那么,我顺便看看 for和while带循环体的
发现for()会有更多的运算