Re: [GD-Windows] VC 2005 Warning C4244
Brought to you by:
vexxed72
|
From: Jon W. <hp...@mi...> - 2007-12-12 19:54:23
|
In the past, I've silenced that kind of compiler warning by explicitly
masking with the range. I e:
u_short n = htons(x) & 0xffff;
The compiler, at the time, was smart enough to realize that the range of
the masked value could never go outside the range of the stored variable.
I honestly forget which compiler it was, though, as it was a while ago,
but I suggest you try it! If it doesn't work for MSVC, then you'll have
to live with disabling 4244.
Cheers,
/ h+
Dan Glastonbury wrote:
> G'Day,
> I'm trying to compile at warning level 4 and I'm getting a lot of
> spurious C4244. This warning is about an integer narrow storing
> possibly loosing information.
>
> The problem is with this kind of code:
>
> u_short n = htons(x);
>
> htons returns a u_short but, as the standard says, the result of
> integer expressions is promoted to int (or unsigned) and is causing
> the warning. Is there anyway I can code it to shut up VC 2005?
>
> u_short n = (u_short)htons(x) doesn't work, because the result is
> still promoted in the context of an expression!
>
> cheers
> DanG
>
>
--
-- Go is to Western chess what philosophy is to double entry accounting.
|