Posts

Showing posts from April, 2017

5 Tips for a less buggy C code

5 Tips for a less buggy C code 1. when comparing a variable to a value in if statement ,always make the value at left-hand side . Normally ,by mistake if  assignment operator (=) is  used instead of equal operator (==) in a comparison , This won’t generate any compilation error but it will generate a logical error . By placing  the value at left-hand side , if assignment operator is used by mistake instead of equal operator , a compilation error will be generated. 2. Never use pointers to decode a message containing more than one signal .This way leads to platform dependant code and reduce code reusability . for example If you have a message consisting of 2 bytes the first byte represents temperature value and the second value represents humidity value .Casting address of the message to a pointer to character to read each signal will generate different result on different endianness systems .At this case it is more safe to use shift operators to read each signal ....