*This is not comprehensive rules...but few common(sense) ideas!
1. If -Else statements Any if statements with an else shall end with else clause if (NULL == p_object) { result =ERR_NUL:L_PTR; } else if (p-object = malloc(sizeof(object_t))) { ....... } else { // Normal processing steps ...... } 2. Variables 2.1 The name for all pointers should begin letter "p", For example, *p_led_reg 2.2 Underscore shall be used to seperate words in variable names ex: int array_count [MAX_COUNT]; 2.3 Each variable should be descriptive of its purpose names. char input_strings; 3. Functions -Like Macros Parameterized macros shall not be used if an inline function can be written to accomplish the same task As per C99, C++ keyword inline added to C. Example // Do not do this #define MAX (A,B) ((A) >(B) ? (A) : (B)) // if you can do this instead inline int max (int num1, int num2) 4. Floating Point 1. Use the [C99] type names float32_t, float 64_t and float128_t. 2. Append 'f' to all single-precession constants . Example pi = 3.1415927f 5. Fixed -Width Intergers Whenever the width, in bits or bytes, of an interger value matters in the program, one of the fixed width data types shall be used in the place of char,short,int, long or long long / Integer width Singed type Unsigned type ___________________________________________________ 8 bits int8_t uint8_t 16 bits int16_t uint16_t 32 bits int32_t unit32_t * Keywords short and long shall not be used
0 Comments
Leave a Reply. |
AuthorCheers! I'm Chandra, . Archives
May 2024
Categories |