Is if(TRUE) a good idea in C?

后端 未结 17 3431
忘了有多久
忘了有多久 2021-02-19 01:19

In the C programming language, it is my understanding that variables can only be defined at the beginning of a code block, and the variable will have the scope of the block it w

17条回答
  •  庸人自扰
    2021-02-19 01:26

    Apparently I'm in the minority, but I find "just braces" much harder to read because it deviates from the usual pattern. On the (admittedly infrequent) occasions where I want a scoped block without defining another function, I prefer to include the "if", but without any macros and with a comment to explain why:

    if( 1 ) // just to establish scope
    {
       // do stuff here
    }
    

提交回复
热议问题