I am a little over the top sometimes when it comes to code formatting lol, i like code to look neat since it makes it easier for us to read and although its different for everyone we need to keep some kind of standard so mine has been a mix of GNU Coding Standards and Drizzle Coding Standards. Although i have to explain the language crules its coding guidelines within the project at the end on its own.
If your an emacs user like me you can't really go wrong, emacs should keep you right, but i have some small things i like to keep the same for example:
NO!
if(a == b && c == j || A) do_something( );
YES!
if( ((a == b) && (c == j)) || A ) do_something( );
NO!
size_t i; for( i= 0; i<strlen("bla"); i++ ) { ... }
YES!
size_t i= 0; for( ; i<strlen("bla"); ++i ) { ... }
Use prefix form (++iter) of the increment and decrement operators with iterators and other template objects. A fairly good explanation why.
NO!
unsigned int x = 7; unsigned int y = 5 + x;
YES!
unsigned int x= 7; unsigned int y= 5 + x;
NO!
ret= function(x,y,z);
YES!
ret= function( x, y , z );
NO!
int foo ( unsigned int param_a, unsigned int param_b, unsigned int param_c ) { printf("some stuff"); if( param_a < param_b ) { printf("...."); } return; }
YES!
int foo( unsigned int param_a, unsigned int param_b, unsigned int param_c ) { printf("some stuff"); if ( param_a < param_b ) { printf("...."); } return; }
/** * @brief * Return the sum of two positive integers. * * @details * Adds x and y and returns the result in z. * * @param[in] x First integer * @param[in] y Second integer * @param[out] z Holds the result of x+y * * @retval 0 success * @retval 1 failure, ints were not positive */ int sum( int x, int y, int *z ) { if( x < 0 || y < 0 ) return 1; *z= x + y; return 0; }