impicit arithmetic conversion warnings

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

impicit arithmetic conversion warnings

1,492 次查看
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?


标签 (1)
0 项奖励
回复
1 回复

667 次查看
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 项奖励
回复