impicit arithmetic conversion warnings

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

impicit arithmetic conversion warnings

1,065 Views
WayneS
Contributor I
Using CW 6.1 compiling for ColdFire V1 of a project that was converted from HCS08 QE128 project.

Why does the following generate warning:
implicit arithmetic conversion from 'int' to 'unsigned short'

typedef unsigned short uint16_t
typedef uint16_t SystemTime_t

SystemTime_t   systemTimeMs;

inline static SystemTime_t ElapsedTime(SystemTime_t startTime)
{
    return systemTimeMs - startTime;
}

it seems to me that all the parameters are clearly defined as 'unsigned short' and there should be no implicit conversions going on?


Labels (1)
0 Kudos
1 Reply

240 Views
CompilerGuru
NXP Employee
NXP Employee

In C, every operation is perfomed with at least int, even if all the operands have a smaller type.
Ask google for "Usual Arithmetic Conversions" for details.
The compiler is right that (unsigned short)-(unsigned short) is a int for the Coldfire processor.
For the HC08, as the unsigned short has the same size as int, the result it a unsigned int.
I guess because short and int have the same size, the HC08 compiler did not issue a warning, but for the CF compiler it makes sence to issue it.

Daniel
0 Kudos