In C macros, should one prefer do { … } while(0,0) over do { … } while(0)?

后端 未结 3 1435
旧时难觅i
旧时难觅i 2021-01-01 20:22

A customer recently performed static analysis of my employer\'s C codebase and gave us the results. Among useful patches was the request to change the famous do { ... } whil

3条回答
  •  走了就别回头了
    2021-01-01 21:07

    Using while(0,0) prevents Microsoft compiler from generating a warning about a condition which is a constant (Warning C4127).

    When this warning is enabled (e.g. with /W4 or /Wall), it can be shut down on a case by case basis with this nice little trick (see this other thread).

    EDIT: Since Visual Studio 2017 15.3, while(0) does not emit warnings anymore (cf. Constant Conditionals). You can get rid of your (0,0) !

提交回复
热议问题