TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

Guideline:  6#1Checked automatically with code checker

Synopsis:Make implicit conversions explicit.
Language:C
Severity Level:2
Category:CONVERSIONS


Description:

An implicit conversion might obscure the behaviour of a program. If implicit conversions are made explicit it is much simpler to understand what is exactly going on. Consider the following piece of code.

Example:

  enum E_ErrorCommandIds {
    ...
  };
  int commandId;

  E_ErrorCommandIds errorCommand = commandId;

The assignment in this example converts an integer implicity into an enumeration. If the integer for some reason is larger than the number of elements of the enumerator the behaviour of the program is undefined. To detect problems in this area as soon as possible it is better to make the cast explicit.

Example:

  enum E_ErrorCommandIds {
    ...
  };
  int commandId;

  E_ErrorCommandIds errorCommand = (E_ErrorCommandIds) commandId;