TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C++ Coding Standard
Search

Rule:  STY#009Checked automatically with code checker

This rule is Obsolete
Synopsis:Braces ("{}") which enclose a block are to be placed in the same column, on separate lines directly before and after the block
Language:C++
Severity Level:10
Category:Style


Description:

This way the beginning and the end of the block can easily be determined.

Exception: This rule does not apply when braces are used in namespaces.

do statement
  • The curly brackets are aligned with the keywords do and while.
  • Example do statement:

    do
    {
        <statement>
    }
    while (expression);
    for statement
  • The curly brackets are aligned with the keyword for.
  • Example for statement:

    for (nCount = 0; nCount < Max(); ++nCount)
    {
        <statement>
    }

    if statement

  • The curly brackets are aligned with the keywords if and else.
  • Example if statement without else statement:

    if (expression)
    {
        <statement>
    }

    Example if statement with else statement:

    if (expression)
    {
        <statement>
    }
    else
    {
        <statement>
    }

    Example if statement with else-if statement:

    if (expression)
    {
        <statement>
    }
    else if (expression)
    {
        <statement>
    }
    else
    {
        <statement>
    }

    switch statement

    • The curly brackets are aligned with the keyword switch.
    • Cases are separated by an empty line.

    Example switch statement:

    switch (expression)
    {
    case <const-expression>:
        <statement>
        break;
    
    case <const-expression>:
        <statement>
        break;
    
    default:
        <statement>
        break;
    }

    try-catch statement

    • The keywords try and catch must be followed by a compound statement ({ .. }), even if no statement must be executed.
    • The curly brackets are aligned with the keywords try and catch.

    Example try-catch statement:

    try
    {
        <statement>
    }
    catch ()
    {
        <statement>
    }

    while statement

  • The curly brackets are aligned with the keyword while.
  • Example while statement:

    while (expression)
    {
        <statement>
    }

    namespaces

    Example:

    namespace Philips {
        ...
        namespace Ixr {
            ...
            namespace IP {
                ...
    }}}


    Literature References:
    Ellemtel Rec. 24