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

Rule:  6.3.aChecked automatically with code checker

Synopsis:Unsafe implicit conversions in expressions, return statements, assignment statements or argument lists shall not be used. Unsafe means: conversions where values are truncated and/or sign can be lost.
Language:C
Severity Level:4
Category:Conversions


Description:

Justification

Implicit conversions are implementation defined, therefore unsafe conversions can have unexpected results.

Example

int i;
unsigned int ui;
long l;
float f;
double d;

l = i; /* RIGHT */
i = l; /* WRONG: value may be truncated */
d = f; /* RIGHT */
ui = i; /* WRONG: sign is lost */
i = f; /* WRONG: possible loss of data */

int f(void)
{
    long l;
    ...
    return l; /* WRONG: value may be truncated */
}

unsigned int g(void)
{
    int i;
    ...
    return i; /* WRONG: sign is lost */
}

void a(double array[100])
{
    for (int i = 0; i < 100; i++)
    {
        array[i] = 0;
    }
}

void b()
{
    double myArray[80];                  
    a(myArray); /* WRONG: elements 81-99 will be written to */
}

Note

Do not explicitly cast safe implicit conversions.