Is there a useful case using a switch statement without braces?

后端 未结 5 514
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 06:24

In H&S5 I encountered the \"most bizarre\" switch statement (8.7.1, p. 277) not using braces.
Here\'s the sample:

switch (x)
    default:
    if (pri         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-13 06:46

    Section 6.8.4.2 The switch statement says:

    A switch statement causes control to jump to, into, or past the statement that is the switch body, depending on the value of a controlling expression, and on the presence of a default label and the values of any case labels on or in the switch body. A case or default label is accessible only within the closest enclosing switch statement.

    The terms switch-body and closest enclosing switch-statement seem not to require braces. So you're right it looks weird but is legal. (Never saw that before)

提交回复
热议问题