mario::konrad
programming / C++ / sailing / nerd stuff
C++ Style: ‘const’ before or after the type
© 2013 / Mario Konrad

Is it better to write the const keyword before or after the data type. Although the style (west const):

const int * a = &b;

is more pleasing to my eyes, the other way arround (writing const after the type, aka. east const) is more consistent:

int const * a = &b;

This way, everything left of const is meant to be const. Example:

int main(int, char**)
{
    int a = 10;

    int const * a0 = &a; // pointer to const int

    int * const a2 = &a; // const pointer to int

    int const * const a1 = &a; // const pointer to const int

    return 0;
}