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

后端 未结 3 1452
旧时难觅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 20:49

    Well, I'll go for an answer:

    Is there a legitimate reason why one should prefer the second form of the macro... ?

    No. There is no legitimate reason. Both always evaluate to false, and any decent compiler will probably turn the second one into the first in the assembly anyway. If there was any reason for it to be invalid in some cases, C's been around far long enough for that reason to be discovered by greater gurus than I.

    If you like your code making owl-y eyes at you, use while(0,0). Otherwise, use what the rest of the C programming world uses and tell your customer's static analysis tool to shove it.

提交回复
热议问题