We use a code checker at work which complains about the following code:
Code:short Rank; .... Rank = SHRT_MIN ;The complaint isCode:// SHRT_MIN is defined as #define SHRT_MIN (-32767-1)
"Values shall not be implicitly converted to a narrower type.
(Category: CONVERSIONS, Level: 1)
Value implicitly converted to narrower type 'short'"
It's even a level 1 meaning that is a nasty bug according to the tool
The tool says that because the expression (-32767-1) yields an int as type and that int is assigned to a short. So the fix to shut the tool up is
and management seems to think this improves code quality. What do you people think? The cast makes better quality code or not?Code:Rank = (short)SHRT_MIN;