Instructions for proper source-code formatting (ANSI-C) ======================================================= goal: easy exchange of source code, improved readability * only one command per line * not more than 70 characters per line avoiding line breaks * enclose basic mathematical operations and equals sign by space characters e.g.: a = b + c; /* right */ a =b+ c; /* wrong */ a *= b; /* right */ a*=b; /* wrong */ * space after comma, e.g.: int i, j, x, y; /* right */ int i,j,x,y; /* wrong */ * enclose comparison operators with spaces if possible e.g.: if (val1 >= val2) ... * space after C keyword e.g.: for ( ...) /* right */ for(...) /* wrong */ if (...) /* right */ if(...) /* wrong */ * function calls e.g.: function_1( parameter1, parameter2); /* right */ function_1 ( parameter1, parameter2); /* wrong */ function_1(parameter1, parameter2); /* wrong */ * loop body and indentions (1 tab = 2 spaces) e.g.: for ( i = 0; i < end_i; i++) { for ( j = 0; j < end_j; j++) { .... } } if ( (x < x_end) && (y < y_end) ) { ... } do { ... } while ( !stop); * comment the more explanations the better, makes reading and modification much easier a) head of source code file one file should contain functions which are closely related to each other /******************************************************************* * * File....: filename.c * Function: short description * Author..: first family name * Date....: 29.02.2009 * 28.04.2010 H.Musterfrau, 32.05.2011, F.Mustermann * ********************************************************************/ b) head of a function /*------------------------------------------------------------------ * function_1() * * short description *-----------------------------------------------------------------*/ void function_1( int parameter1, float parameter2) { int i, x; /* Declaration */ float val; /* at least one empty line */ i = 0; val = (float)i; . . . } c) comment for a program section a = b; /* * Processing of sub signals * under consideration ... * */ c = func_ab( ...); d = func_ac( ...); d) comment for single program line, put comment environment ( /* */) with tab stops if possible vec_len_h = vec_len >> 1; /* half vektor length */ process_signal( signal, vec_len_h); /* process signal */ e) put comment before the source code line to avoid more than 70 characters /* this comment would not fit the line below anymore */ process_signal( signal, vec_len_h, wertz, qsedrf, wwwwww);