C Switch-case curly braces after every case

前端 未结 5 1835
感动是毒
感动是毒 2020-12-08 02:07

In a C switch-case flow control, it\'s required to put curly braces { } after a case if variables are being defined in that block.

5条回答
  •  独厮守ぢ
    2020-12-08 02:46

    Generally it is bad practice jump over the initialization of a variable, be it with goto or switch. This is what happens when you don't have the the blocks per case.

    There is even a case in C99 where jumping over the initialization is illegal, namely variable length arrays. They must be "constructed" similarly as non-PODs in C++, their initialization is necessary for the access of the variable later. So in this case you must use the block statement.

提交回复
热议问题