e101.sg
  • About
  • Blog
  • Podcast
  • Useful-Links
  • About
  • Blog
  • Podcast
  • Useful-Links

5 useful rules for coding standard  - C/C++

27/1/2017

0 Comments

 
*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

#Event_Photos

15/1/2017

0 Comments

 
Happy New Year !  Here is some of photos of  events which i attended.
1. Cybertech 2016 
​2. SCS  Industry talk on cybertech -Nov 2016
​3. ST Eng - Seminar - Dec 2016
​4. IoTSG - Meetup group monthly talk on Sixfox - Jan 2017 
​5. SCS Career guidance program TESA - October 2016
0 Comments

    Author

    Cheers! I'm Chandra, . 
    Passion for embedded system and programming. Interest include Arduino, R'Pi, Internet of Things, Machine learning etc,.
    At the moment working as Research Engineer at SIT, Singapore.


    Picture

    Archives

    March 2023
    January 2023
    September 2022
    August 2022
    February 2022
    January 2022
    May 2021
    March 2021
    January 2021
    August 2020
    June 2020
    May 2020
    March 2019
    February 2019
    January 2019
    November 2018
    May 2018
    April 2018
    January 2018
    October 2017
    June 2017
    May 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    May 2016
    March 2016
    September 2015
    July 2015
    March 2015
    November 2014

    Categories

    All
    Photos

    RSS Feed

    View my profile on LinkedIn