Click here to Skip to main content
12,887,625 members (31,627 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


11 bookmarked
Posted 14 Nov 1999

Braces and brackets

, 3 Nov 2000 CPOL
Rate this:
Please Sign up or sign in to vote.
Options for placing braces

Options for Parentheses

Option 1: Spaces between inside and outside the parentheses. 

if ( something )

Option 2: Spaces outside parentheses, no space inside.

if (something)

Option 3: Spaces inside parentheses, no space outside.

if( something )

Option 4: No white space.


Options for braces

Option 1: Braces starting on control line.

if (something) {
  // statements

Option 2: Braces starting on line under control line, non-indented.

if (something) 
    // statements

Option 3: Braces starting on line under control line, indented.

if (something) 
    // statements

Option 4: Braces starting on control line, closing brace indented.

if (something) {
    // statements


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Chris Maunder
Founder CodeProject
Canada Canada
Chris is the Co-founder, Administrator, Architect, Chief Editor and Shameless Hack who wrote and runs The Code Project. He's been programming since 1988 while pretending to be, in various guises, an astrophysicist, mathematician, physicist, hydrologist, geomorphologist, defence intelligence researcher and then, when all that got a bit rough on the nerves, a web developer. He is a Microsoft Visual C++ MVP both globally and for Canada locally.

His programming experience includes C/C++, C#, SQL, MFC, ASP, ASP.NET, and far, far too much FORTRAN. He has worked on PocketPCs, AIX mainframes, Sun workstations, and a CRAY YMP C90 behemoth but finds notebooks take up less desk space.

He dodges, he weaves, and he never gets enough sleep. He is kind to small animals.

Chris was born and bred in Australia but splits his time between Toronto and Melbourne, depending on the weather. For relaxation he is into road cycling, snowboarding, rock climbing, and storm chasing.

You may also be interested in...

Comments and Discussions

QuestionHow about spaces Pin
AlexMarbus27-Feb-01 7:27
memberAlexMarbus27-Feb-01 7:27 
AnswerRe: How about spaces Pin
Jason Douglas2-Mar-01 3:38
memberJason Douglas2-Mar-01 3:38 
AnswerRe: How about spaces Pin
Anonymous2-Mar-01 6:05
memberAnonymous2-Mar-01 6:05 
GeneralRe: How about spaces Pin
James R. Twine4-Mar-01 7:51
memberJames R. Twine4-Mar-01 7:51 
> I use this
> if( a )

   Same for me.  Same goes for function calls, and brackets.  I also tend to space out "pointer to member".  My spacing looks like this:

    CSomeObj    *pObj = m_soaSomeObjectArray[ 2 ];  // Get Object From Array...
    if( pObj )                                      // If We Have An Object
        pObj -> CallThisFunction(...);              // Call Function
        _ASSERTE( sizeof( wchar_t ) == 2 );         //(In)Sanity Check...
        ::_putts( _T( "Write out THIS!" ) );        // Yell At User


-=- James.
AnswerRe: How about spaces Pin
Simon Hughes2-Apr-01 0:24
memberSimon Hughes2-Apr-01 0:24 
AnswerRe: How about spaces Pin
Yoko1-May-01 4:06
memberYoko1-May-01 4:06 
AnswerRe: How about spaces Pin
James Pullicino4-May-01 4:45
memberJames Pullicino4-May-01 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 4 Nov 2000
Article Copyright 1999 by Chris Maunder
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid