c-programming:style:start
Style
/*****************************************************************************/ // Keep the length of source lines to 79 characters or less // Put the open-brace that starts the body of a C function in column one // Don’t leave white spaces at the end of lines // Indentations are 4 characters // tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent termguicolors number // Don't indent more than 3 levels // The preferred way to ease multiple indentation levels in a switch statement // is to align the switch and its subordinate case labels in the same column // instead of double-indenting the case labels switch (suffix) { case 'G': case 'g': mem <<= 30; break; case 'M': case 'm': mem <<= 20; break; case 'K': case 'k': mem <<= 10; fallthrough; default: break; } // Always uses braces for multiple statements // Put the opening brace last on the line, and put the closing brace first // This applies to all non-function statement blocks: // if, switch, for, while, do if (condition) { do_this(); do_that(); } // Only functions have the opening brace at the beginning of the next line int function(int x) { body of function } // Closing brace is empty on a line of its own, except in the cases where // it is followed by a continuation of the same statement do { body of do-loop } while (condition); if (x == y) { .. } else if (x > y) { ... } else { .... } // Do not use braces where a single statement will do if (condition) action(); if (condition) do_this(); else do_that(); // This does not apply if only one branch of a conditional statement is // a single statement; in the latter case use braces in both branches if (condition) { do_this(); do_that(); } else { otherwise(); } // Also, use braces when a loop contains more than a single simple statement while (condition) { if (test) do_something(); } // Use a space after these keywords: // if, switch, case, for, do, while // but not with sizeof, typeof, alignof, or __attribute__ // Do not add spaces around (inside) parenthesized expressions s = sizeof(struct file); // Use one space around (on each side of) most binary and ternary operators // = + - < > * / % | & ^ <= >= == != ? : // But no space after unary operators: // & * + - ~ ! sizeof typeof alignof __attribute__ defined // no space before the postfix increment & decrement unary operators // no space after the prefix increment & decrement unary operators // ++ -- // no space around the . and -> structure member operators // Functions should fit on one or two screenfuls of text (80x24) // They shouldn’t exceed 5-10 local variables // Separate functions with one blank line. If the function is exported, // the EXPORT macro for it should follow immediately after the closing // function brace line int system_is_up(void) { return system_state == SYSTEM_RUNNING; } EXPORT_SYMBOL(system_is_up); // Function prototypes should include parameter names with their data types // Use the double forward slash (//) for all comments // Use multi-line comments within /* and */ for disabling code blocks // Never use numbers other than 1 and 0 in your code. If you // require another numeric constant you should make it a const variable
c-programming/style/start.txt · آخرین ویرایش: 2024/04/19 17:51 توسط pejman
