Re: VC 2005 Warning C4244
Jon Watte <[email protected]> Wed, 12 Dec 2007 11:27:44 -0800
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
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.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555