c_language:c_style
Table of Contents
Misc
C and C++ Style Guides – Archived version of a collection of style guides
libevent – Available API to maybe seek inspiration from. Uses callbacks and stuff.
Embedded C Coding Standard – By Michael Barr
Things to consider
Naming
int variable, descriptive_variable_name; typedef int own_datatypes_t; void function_names(void); void mylib_library_function_with_prefix(void); typedef enum myenum_t { MYLIB_GLOBAL_SCOPE_ENUM, } myenum_t; const int constant; #define ANY_DEFINE_OR_MACRO
Embracing
void foo(void) { } if(a) { } switch(a) { case A: break; case B: case C: break; default: break; }
Conditional statement whitespaces
if(a == b) // Not any of these if (a == b) if( a == b ) // Compare to function call strlen (str) strlen( str )
Whitespaces in declarations
uint32_t *my_func(); uint32_t* my_func(); uint32_t * my_func(); uint32_t *my_var; uint32_t* my_var; uint32_t * my_var; uint32_t *my_var, *another_var, third_var; void a_function_with_a_really_long_name_and_argument_list(int that, int makes, int you, int wonder, int where int and_how, int to, int break_the, int lines);
Program flow
- Should functions only have one return statement? How/when/why?
c_language/c_style.txt · Last modified: 2022/09/12 00:30 by 127.0.0.1
