Thread: [GD-Windows] VC 2005 Warning C4244
Brought to you by:
vexxed72
From: Dan G. <dan...@gm...> - 2007-12-12 12:21:46
|
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 -- Dan Glastonbury, Dan dot Glastonbury at gmail dot com `Pour encourjay lays ortras' |
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. |
From: Jesus de S. G. <jes...@gm...> - 2007-12-13 00:01:23
|
Hmm... I am not having warnings in code like that with Visual Studio 2005 SP1 and W4... strange, isn't it? On Dec 12, 2007 12:56 PM, Dan Glastonbury <dan...@gm...> 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 > > -- > Dan Glastonbury, Dan dot Glastonbury at gmail dot com > `Pour encourjay lays ortras' > > ------------------------------------------------------------------------- > 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://sourceforge.net/services/buy/index.php > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |
From: Jeff G. <jef...@ho...> - 2007-12-13 20:51:13
|
You can disable the warning using a #pragma: =20 #pragma warning(disable : 4244)//double to floatenjoy =20 =20 =20 > Date: Wed, 12 Dec 2007 21:56:34 +1000> From: dan...@gm...> T= o: gam...@li...> Subject: [GD-Windows] VC 200= 5 Warning C4244> > 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 =3D htons(x);> > htons returns a u_short but, as the sta= ndard says, the result of> integer expressions is promoted to int (or unsig= ned) and is causing> the warning. Is there anyway I can code it to shut up = VC 2005?> > u_short n =3D (u_short)htons(x) doesn't work, because the resul= t is> still promoted in the context of an expression!> > cheers> DanG> > --= > Dan Glastonbury, Dan dot Glastonbury at gmail dot com> `Pour encourjay l= ays ortras'> > ------------------------------------------------------------= -------------> 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 ab= out anything Open Source.> http://sourceforge.net/services/buy/index.php> _= ______________________________________________> Gamedevlists-windows mailin= g list> Gam...@li...> https://lists.sourcefor= ge.net/lists/listinfo/gamedevlists-windows> Archives:> http://sourceforge.n= et/mailarchive/forum.php?forum_id=3D555 _________________________________________________________________ Get the power of Windows + Web with the new Windows Live. http://www.windowslive.com?ocid=3DTXT_TAGHM_Wave2_powerofwindows_122007= |
From: Dan G. <dan...@gm...> - 2007-12-13 22:46:21
|
> You can disable the warning using a #pragma: > > #pragma warning(disable : 4244)//double to float Sure, I know I can disable the warning. But I was looking for a way of not disabling the warning. I want to know about legitimate problems, but in this case of assigning the result of a function that returns a short to a short variable this warning is spurious. cheers DanG -- Dan Glastonbury, Dan dot Glastonbury at gmail dot com `Pour encourjay lays ortras' |
From: Mat N. <mat...@bu...> - 2008-01-16 19:20:57
|
If the error message is "warning C4244: 'argument' : conversion from 'long'= to 'u_short', possible loss of data" or the equivalent, then 'x' is not a = u_short or smaller. Otherwise, this compiles without warnings in an otherwise empty VS2005 cons= ole project. MSN -----Original Message----- From: gam...@li... [mailto:gamedevlis= ts-...@li...] On Behalf Of Dan Glastonbury Sent: Thursday, December 13, 2007 2:46 PM To: Game Development for MS Windows Subject: Re: [GD-Windows] VC 2005 Warning C4244 > You can disable the warning using a #pragma: > > #pragma warning(disable : 4244)//double to float Sure, I know I can disable the warning. But I was looking for a way of not disabling the warning. I want to know about legitimate problems, but in this case of assigning the result of a function that returns a short to a short variable this warning is spurious. cheers DanG -- Dan Glastonbury, Dan dot Glastonbury at gmail dot com `Pour encourjay lays ortras' ------------------------------------------------------------------------- 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/marketplac= e _______________________________________________ Gamedevlists-windows mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=3D555 |
From: Pierre T. <pie...@gr...> - 2008-03-17 08:37:42
|
Hi, I got a report saying one of my programs displayed this error message on a WinXP machine: http://www.consumingexperience.com/2007/11/windows-no-disk-exception-processing.html Problem is: I have no idea why. I ran the same program on many different machines without ever seeing this dialog box. At first I thought it would be a simple bug like trying to access a file like "c:\somefile.dat" on a machine that doesn't have a C: drive. However I made a simple test doing exactly this, and it ran fine. I can't debug on the client's machine, so I need to guess what's wrong in my code. Any idea? Under what circumstances will the above error message get displayed? Thanks, - Pierre |
From: Chris C. <ch...@bl...> - 2008-03-17 11:36:24
|
Not sure about the specifics of the error dialog, but it would be interesting to know what was generating it - low level from inside a system call, or generated by your code as a response to a standard error? Is the user running the same anti-virus software? In my experience looking over crash reports from end-user machines (usually sporadic crash reports from PCs used by hospital staff), there was often interference with disk access. We never nailed down an exact diagnosis, but we inferred that if the app was trying to access the file system in an odd or low level way, the AV might be interpreting that as a viral attack and blocking it, or at least changing the access characteristics enough to cause a crash. We added a switch to swap some of the more low level disk usage that we'd put in for performance reasons for standard file calls to the next version in an attempt to improve compatibility. Never stayed with the product for long enough to find out whether it fixed their problem though, sorry. Chris Chapman (Director) Black Company Studios On Mon, Mar 17, 2008 at 8:37 AM, Pierre Terdiman <pie...@gr...> wrote: > Hi, > > I got a report saying one of my programs displayed this error message on a > WinXP machine: > > http://www.consumingexperience.com/2007/11/windows-no-disk-exception-processing.html > > Problem is: I have no idea why. I ran the same program on many different > machines without ever seeing this dialog box. > > At first I thought it would be a simple bug like trying to access a file > like "c:\somefile.dat" on a machine that doesn't have a C: drive. However > I > made a simple test doing exactly this, and it ran fine. > > I can't debug on the client's machine, so I need to guess what's wrong in > my > code. > > Any idea? Under what circumstances will the above error message get > displayed? > > Thanks, > - Pierre > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |
From: Jon W. <hp...@mi...> - 2008-03-17 18:57:26
|
My guess is it's some other software installed on that machine. An anti-virus package, a disk utility, or even some malware. Your program then appears to trigger whatever the bad behavior is, but it's not caused by your software as such. To debug this, I would add a __try/__except handler around my entire WinMain, and have the exception handler write out a minidump with indirectly referenced memory, and then tell the user to send that to me. Visual Studio Professional can open minidumps and debug them much like a regular program, which is pretty slick. Sincerely, jw Pierre Terdiman wrote: > Hi, > > I got a report saying one of my programs displayed this error message on a > WinXP machine: > http://www.consumingexperience.com/2007/11/windows-no-disk-exception-processing.html > > Problem is: I have no idea why. I ran the same program on many different > machines without ever seeing this dialog box. > |
From: Chris C. <ch...@bl...> - 2008-03-18 09:42:00
|
I've not used mini-dumps before, but if it's not already included in that, then it is useful to dump out and send a list of all processes running on the machine as well to aid in diagnosis. Chris Chapman (Director) Black Company Studios On Mon, Mar 17, 2008 at 6:57 PM, Jon Watte <hp...@mi...> wrote: > > My guess is it's some other software installed on that machine. An > anti-virus package, a disk utility, or even some malware. Your program > then appears to trigger whatever the bad behavior is, but it's not > caused by your software as such. > > To debug this, I would add a __try/__except handler around my entire > WinMain, and have the exception handler write out a minidump with > indirectly referenced memory, and then tell the user to send that to me. > Visual Studio Professional can open minidumps and debug them much like a > regular program, which is pretty slick. > > Sincerely, > > jw > > > Pierre Terdiman wrote: > > Hi, > > > > I got a report saying one of my programs displayed this error message on a > > WinXP machine: > > http://www.consumingexperience.com/2007/11/windows-no-disk-exception-processing.html > > > > Problem is: I have no idea why. I ran the same program on many different > > machines without ever seeing this dialog box. > > > > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > |