[Nfd-dev] code-style: switch with compound statement

Junxiao Shi shijunxiao at email.arizona.edu
Wed Aug 12 14:11:47 PDT 2015


Dear folks

Incorporating suggestions from Eric and Wentao:

// option E
switch (cond) {
  case 1:
  {
    int i = 1;
    doSomething(i);
    // Fallthrough
  }

  case 2:
  {
    doSomething(2);
    break;
  }

  case 3:
  {
    int j = 3;
    doSomething(j);
    break;
  }

  default:
  {
    doSomething(0);
    break;
  }
}

• When any ‘case’ or ‘default’ contains a declaration and therefore needs a compound statement, all ‘case’s and ‘default’ must use compound statements.
• When using compound statements, ‘case’ and ‘default’ should be indented two spaces after ‘switch’, ‘{‘ and ‘}’ of the compound statements are indented at the same level as ‘case’ and ‘default’, and statements within the compound statements are indented two spaces after ‘case’ and ‘default’.
• ‘break’ and ‘// Fallthrough’ should be placed inside compound statements.

A ‘switch’ statement without compound statements should still be formatted in the current way, i.e. no extra indentation for ‘case’ and ‘default’.

Any more comments?

Yours, Junxiao
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/nfd-dev/attachments/20150812/3a921aed/attachment.html>


More information about the Nfd-dev mailing list