Coding style

From CodeBlocks
Revision as of 14:06, 14 December 2005 by Mandrav (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

NOTE: this is yet unfinished

The following are guidelines for the code formatting to use in Code::Blocks (C::B) source code. Anyone writing code or a patch for C::B, is required to follow these.

The general coding style is the ANSI one:


namespace FooSpace
    int Foo()
        if (isBar)
            return 1;
            return 0;

Variables naming

Non-class member variables should use capital letter at the start of each word, except for the first.

Class member variables should start with m_. If the variable is a pointer, use m_p as a prefix. Following the prefix is the variable's name. Use descriptive names and use capital letters at the start of each word (the first too). So a fictious variable holding a value for position would be named as m_ValueForPosition.


// Good
int aLocalVar;
int m_SomeInt;
void* m_pSomePointer;

// Bad
int SomeInt; // either no m_ prefix if it's a class variable, or capital first letter if it's a local variable
int m_someInt; // no capital letter 'S'
void* m_SomePointer; // no m_p prefix

Variables declaration

One variable declared each time on a different line. For pointer/reference variables, put the * or & right after the type not before the variable name.


// Good
int& someInt;
void* pPtr;

// Bad
int &someInt; // & not after type
void* pPtr, pSomeOther; // multiple declarations in one line