>>    Home Contact Printable Version
  Start Services Assessments Tools Training Download  
Automated Error Prevention
 

Coding Standards
Examples of simple rules for C/C++
  • Initialise all variables
    A classical source of errors. Using uninitialised variables can lead to unexpected results that are very difficult to track down.
  • Avoid assignment in 'if' statement condition
    Mixing '=' and '==' is another classical source of errors in C.
  • Use 'new' and 'delete' instead of 'malloc' and 'free'
    'malloc' and 'free' don't know about constructors and destructors. As a consequence, not using 'new' and 'delete' may result in losing memory.
  • List members in an initialisation list in the order in which they are declared
    Class members are initialized in the order of their declaration in the class, not in the order they are listed in a member initialization list. It will result in an error if you try to use a member to initialise another one in the initialization list.
  • Prefer C++-style casts
    Programs that use C++-style cast are easier to read and allow compilers to detect more easily casting errors.
  • Do not use tabs
    A very basic rule. Of course using tabs will never result in an error but because text editors don't have the same way of handling tabs, reading "tabulated code" may turn out to be a very painful task.
Commonly used Coding Standards for C/C++

Articles and Books


Other related links

Visit our partner sites