f



Getting rid of warnings

I am trying to get rid of a few annoying warnings in my project - I have got 
rid of most of them but a few remain which I cant seem to get rid of.  The 
first one is while using FD_SET/FD_CLR for adding and clearing sockets.  I 
get the warning:
 warning C4127: conditional expression is constant

The other one is using SetWindowLongPtr.  I did have two warnings for this 
but managed to cast the result to get rid of one warning.  I cant get rid of 
the last warning though.  My code is:
mOldWndProc = (WNDPROC)(long long)SetWindowLongPtr(mHwnd, GWLP_WNDPROC, 
(LONG_PTR)SkinWndProc);

Where SkinWndProc is defined as:
 LRESULT CALLBACK SkinWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, 
LPARAM lParam)

and the warning is:
 warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible 
loss of data

If anybody can help I would be very grateful.

Many Thanks
Allan


0
Allan
3/30/2006 5:52:44 PM
comp.os.programmer.win32 14523 articles. 0 followers. Post Follow

5 Replies
415 Views

Similar Articles

[PageSpeed] 7

Allan M. Bruce wrote:
> I am trying to get rid of a few annoying warnings in my project - I have got 
> rid of most of them but a few remain which I cant seem to get rid of.  The 
> first one is while using FD_SET/FD_CLR for adding and clearing sockets.  I 
> get the warning:
>  warning C4127: conditional expression is constant

Show us that conditional expression

> 
> The other one is using SetWindowLongPtr.  I did have two warnings for this 
> but managed to cast the result to get rid of one warning.  I cant get rid of 
> the last warning though.  My code is:
> mOldWndProc = (WNDPROC)(long long)SetWindowLongPtr(mHwnd, GWLP_WNDPROC, 
> (LONG_PTR)SkinWndProc);

mOldWndProc = (WNDPROC)SetWindowLongPtr(mHwnd, GWLP_WNDPROC,(LONG_PTR)SkinWndProc);
or just:
mOldWndProc = SetWindowLongPtr(mHwnd, GWLP_WNDPROC,(LONG_PTR)SkinWndProc);

> 
> Where SkinWndProc is defined as:
>  LRESULT CALLBACK SkinWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, 
> LPARAM lParam)
> 
> and the warning is:
>  warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible 
> loss of data
> 
> If anybody can help I would be very grateful.
> 
> Many Thanks
> Allan
> 
> 

-- 
677265676F727940346E6575726F6E732E636F6D
0
ISO
3/30/2006 7:32:27 PM
> Show us that conditional expression

The conditional expression is FD_SET(mSocket, &mMasterSet)

>> mOldWndProc = (WNDPROC)(long long)SetWindowLongPtr(mHwnd, GWLP_WNDPROC, 
>> (LONG_PTR)SkinWndProc);
>
> mOldWndProc = (WNDPROC)SetWindowLongPtr(mHwnd, 
> GWLP_WNDPROC,(LONG_PTR)SkinWndProc);
> or just:
> mOldWndProc = SetWindowLongPtr(mHwnd, GWLP_WNDPROC,(LONG_PTR)SkinWndProc);

The warning is produced for the last arguement, not the return of 
SetWindowLongPtr.  I must add I am using warning level 4 to show maximum 
warnings.

Allan 


0
Allan
3/30/2006 11:40:32 PM

Allan M. Bruce wrote:
>>Show us that conditional expression
> 
> 
> The conditional expression is FD_SET(mSocket, &mMasterSet)

This warning: "warning C4127: conditional expression is constant" is shown as a result of constant expression in condition check for example:
conts int A=2;
....
if(A) 

or:
while(A!=3)

and so on

FD_SET is macro. I checked how it's defined in winsock.h and the definition is:
#define FD_SET(fd, set) do { \
    if (((fd_set FAR *)(set))->fd_count < FD_SETSIZE) \
        ((fd_set FAR *)(set))->fd_array[((fd_set FAR *)(set))->fd_count++]=(fd);\
} while(0)

You can't get rid of this warning on level 4 when using this macro. But you may replace it with your own macro or function if you don't want to see that warning.

>>>mOldWndProc = (WNDPROC)(long long)SetWindowLongPtr(mHwnd, GWLP_WNDPROC, 
>>>(LONG_PTR)SkinWndProc);
>>
>>mOldWndProc = (WNDPROC)SetWindowLongPtr(mHwnd, 
>>GWLP_WNDPROC,(LONG_PTR)SkinWndProc);
>>or just:
>>mOldWndProc = SetWindowLongPtr(mHwnd, GWLP_WNDPROC,(LONG_PTR)SkinWndProc);
> 
> 
> The warning is produced for the last arguement, not the return of 
> SetWindowLongPtr.  I must add I am using warning level 4 to show maximum 
> warnings.

I don't see here any cast from LONG_PTR to LONG.
Do you get this warning when you just call "SetWindowLongPtr(mHwnd, GWLP_WNDPROC,(LONG_PTR)SkinWndProc);"?
Why do you have such weird cast of return value (to long long and then to WNDPROC)? 

-- 
677265676F727940346E6575726F6E732E636F6D
0
ISO
3/31/2006 2:07:19 AM
> I don't see here any cast from LONG_PTR to LONG.
> Do you get this warning when you just call "SetWindowLongPtr(mHwnd, 
> GWLP_WNDPROC,(LONG_PTR)SkinWndProc);"?
> Why do you have such weird cast of return value (to long long and then to 
> WNDPROC)?

If I dont cast the result I get an error and a warning:
warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible 
loss of data
error C2440: '=' : cannot convert from 'LONG' to 'WNDPROC'

if I cast the result with just (WNDPROC) then I get two warnings:
warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible 
loss of data
warning C4312: 'type cast' : conversion from 'LONG' to 'WNDPROC' of greater 
size

So, thats why I have two casts - I thought this was ugly but MS use this 
kind of trick quite a lot.  If only I could get rid of that warning for the 
last arguement...

Allan 


0
Allan
3/31/2006 8:43:21 AM
"Allan M. Bruce" <allanmb@TAKEAWAYdsl.pipex.com> wrote in message
news:2bWdnYUVHu6ehrHZRVnyrw@pipex.net...
> I am trying to get rid of a few annoying warnings in my project - I have
got
> rid of most of them but a few remain which I cant seem to get rid of.  The
> first one is while using FD_SET/FD_CLR for adding and clearing sockets.  I
> get the warning:
>  warning C4127: conditional expression is constant
>
> The other one is using SetWindowLongPtr.  I did have two warnings for this
> but managed to cast the result to get rid of one warning.  I cant get rid
of
> the last warning though.  My code is:
> mOldWndProc = (WNDPROC)(long long)SetWindowLongPtr(mHwnd, GWLP_WNDPROC,
> (LONG_PTR)SkinWndProc);
>
> Where SkinWndProc is defined as:
>  LRESULT CALLBACK SkinWndProc(HWND hWnd, UINT uMessage, WPARAM wParam,
> LPARAM lParam)
>
> and the warning is:
>  warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG',
possible
> loss of data
>
> If anybody can help I would be very grateful.
>
> Many Thanks
> Allan
>
>

Check this link:
http://pluralsight.com/blogs/keith/archive/2005/01/13/4940.aspx

A short description of your LONG_PTR/LONG problem, and a least the cause if
not the solution :-).


0
Barry
4/2/2006 1:21:01 PM
Reply:

Similar Artilces:

How do I get rid of this warning?
Patterned after the solution suggested in the perlmodlib man page, I wrote the following code: ==================== This is file b.pm #!/usr/local/bin/perl -w use strict; package b; sub f { print "BBBBBBBB @_\n"; } eval join('', <main::DATA>) || die $@ unless caller(); 1 __END__ package main; b::f(@ARGV); ================================= When called this from the command line, say: b.pm X it works fine. But when I use it as a module, say from this context: ===================== This is file p.pl #!/usr/local/bin/perl -w use strict; use b; b::f('X'); ====...

How to get rid of warnings?
I have the maximum number of warnings during PHP development. How can I get rid of these warnings without turning them off in PHP? Here's the code I have: <form method="POST" action="eat.php"> <select name="lunch[ ]" multiple> <option value="pork">BBQ Pork Bun</option> <option value="chicken">Chicken Bun</option> <option value="lotus">Lotus Seed Bun</option> <option value="bean">Bean Paste Bun</option> <option value="nest">Bird-Nest Bun</op...

get rid of warning
After I download some software from a place like macupdate, I install it and then I try it out. But first I get a warning: "such and such app" was downloaded from the internet are you sure you want to open it? Yes, I *know* I downloaded it from the internet. I chose to. And yes, I *do* want to open it � that's why I double clicked it! Is there a place where I can choose to not have those warnings? (iMac, 2.66GHz, 4GB RAM, 10.5.7) -- Michael Fogler http://MichaelFogler.com In article <guitarist-6DC91C.08070308072009@netnews.insightbb.com>, Michael Fogler <gui...

getting a warning about gets
I'm getting a warning on my linux gcc compiler: /tmp/ccXgHa9s.o(.text+0x48): In function `main': : warning: the `gets' function is dangerous and should not be used. And here's where I used gets: #include "common.h" //common.h includes string.h .... .... int main(void) { char zf_name[50]; .... printf("Enter the name of the file\n"); gets(zf_name); ... return 0; } On May 19, 10:38=A0am, pereges <Brol...@gmail.com> wrote: > I'm getting a warning on my linux gcc compiler: > > /tmp/ccXgHa9s.o(.text+0x48): In function ...

What is the meaning of this warning, and how do I get rid of it?
I have a portion of code along the following lines: volatile unsigned char x ; unsigned int f(unsigned char *y) ; When I do unsigned int z = f(&x) ; the compiler issues the following warning: warning: passing arg 1 of `f' discards qualifiers from pointer target type What does this exactly mean? How do I change my code so that the compiler is happy about it? James H. Newman wrote: > I have a portion of code along the following > lines: > > volatile unsigned char x ; &g...

How to Get Rid of Orange Warnings
I ran this exact code earlier this week and it took awhile, but it finally worked. Now when I try and run it, it gives me an error. Can anyone figure out what would be going wrong? Thankss! clear clc theta1=.3; k=18.4; alpha=k/1703703.704; N=.5; for h=50:90; for j=100:500; for LR= 100:250; for l= 1:150; L=l*.01; V=.0001*j; a1=(V*L)/alpha; a0=((2*h*L)/k)*(LR); lmda1=(a1 + (sqrt((a1^2)+4*a0)))/2; lmda2=(a1 - (sqrt((a1^2)+4*a0)))/2; c1=(theta...

Warning from Amos: how to get rid of it
Hi! My Amos lisence expired. I removed the program since the next version is available soon. Now a window (blue stripe above with text "SPSS for Windows" and a yellow ! triangle on gray background with remark "One of the required keys (launch or Menu) for application Amos4-0 was missing. No menu item will be added for it." Followed by OK button) appears in every start. Clicking OK-button in the box lets me to continue, but I would like to have it normal again. Suggestions? Erkki _________________________________________________________________ gsm 040-50...

How do you get rid of useless warnings?
<rant> I'm getting awfully tired of constant warnings about what's going to happen at some point in the future. Warnings like this: ./surfplot.py:313: Warning: 'with' will become a reserved keyword in Python 2.6 And this: /usr/lib/python2.5/site-packages/scipy/linalg/__init__.py:32: DeprecationWarning: NumpyTest will be removed in the next release; please update your code to use nose or unittest And so on... _I'm_not_using_Python_2.6_. When I decided to switch to 2.6, I'll worry about what works and doesn't work in 2.6. In the meantime, how do I...

How to get rid off warnings/errors
Hi members, I'm using the barrayserver which works perfect for my use. I use it the following way : auStruct := {{"van", "N", 10, 3},; {"tot", "N", 10, 3},; {"wanddikte", "N", 5, 2},; {"diameter", "N", 10, 3}} SELF:ohoogte:=bArrayServer{auStruct,,BINACTIVE} SELF:ohoogte:Append() SELF:ohoogte:van:=5.1 Now in an attempt to clean up my code i set the compiler in the "warnings as error" mode. Now it complains that : 1. Variable VAN in entity xxxx is not ...

Get Rid of Warning Box
Hello: I just upgraded to VB 6.0 (late bloomer)..anyway, I am using the datagrid control and when the user does not fill in a specific cell, I don't want the changes saved. So, I put a procedure in the "BeforeUpdate" event and allow the user to choose to fill in the cell or not save the newly inserted (or changed) information. However, after the msgbox asks the user to make a decision, the system also sends a popup that says "Action is Cancelled"...I don't want that "Action is Cancelled" popup...how do I suppress it? I also noted that there is no...

Getting rid of a File Download warning
Hello Everyone, I have consoles on a network that have Auto log-on scripts running. Part of the log-on script is that a ".lnk" file be opened, but a warning message from Windows XP comes up saying that these filetype can contain malicious code and the user can choose if he will open the file or cancel it. The checkbox (always ask before open...) is grayed out and can not be changed. The whole point of the auto log-on scripts is that the sailors don't have to do anything to get the app running. Does anyone know how to disable that warning in XP for a ".lnk"...

how to get rid of warnings from required fields?
Hi, I made a form based on one table that has several required fields. If in the form, I leave some of them blank and close the form using 'X', I get 2 warning messages, 1st is "... field is required." 2nd is "if you close, the data will be lost." How can I get rid of these or, if possible, I would like to replace them with my own. I tried Form Close event, doesn't work. Anyone could help me here? Thanks in advance. ming On 13 May 2006 15:42:39 -0700, swingingming wrote: > Hi, I made a form based on one table that has several required fields. > If in th...

How to get rid of obsolete function warning
Hi all, Since I'm using randint function I receive: Warning: This is an obsolete function and may be removed in the future. Please use RANDI instead. To disable this warning, type warning('off','comm:obsolete:randint'); but everytime I startup MATLAB I have to do "warning('off','comm:obsolete:randint');" How can I get rid of that warning permanently? Elnaz "Elnaz " <ebsadeghian@gmail.com> wrote in message <kjvlb2$6op$1@newscl01ah.mathworks.com>... > Hi all, > Since I'm using ...

Web resources about - Getting rid of warnings - comp.os.programmer.win32

Storm Warning (2007 film) - Wikipedia, the free encyclopedia
Rob and Pia, a couple who are out for a day of sailing become lost in a heavy storm and end up on a desolate island. They come across a barn ...

WARNING: Malware Targets Brazil’s Facebook Users
Microsoft discovered malware aimed at obtaining Facebook users’ login information and taking over their accounts, and the new malware strain, ...

Queensland weather: Severe thunderstorm warning, more tipped for Australia Day
Bureau of Meteorology issues severe thunderstorm warning for large hail, damaging wind and possible flash flooding in parts of the state's South-east. ...

Severe thunderstorm warning for south east
Damaging storms are predicted for the Somerset, South Burnett and Toowoomba council areas on Monday afternoon.

Severe thunderstorm warning with heavy rain and hail
THE Bureau of Meteorology has issued a severe thunderstorm warning for heavy rainfall and large hailstones.

Severe thunderstorm weather warning issued for Canberra region
A severe thunderstorm warning has been issued for the Canberra region

Weather bureau issues flash flooding warning for northern Victoria
Flash flooding is imminent in Victoria's north on Wednesday, with up to 30 millimetres of rainfall expected in some areas.

Severe thunderstorm warning for south east
Damaging storms are predicted for the Somerset, South Burnett and Toowoomba council areas on Monday afternoon.

Tasmania bushfires: Emergency warning for Nelson Bay, Arthur River and Temma in state's north-west
Residents evacuated to a beach on Tasmania's west coast amid reports two homes have been destroyed by a bushfire.

'Duct tape challenge': Washington mom issues warning after son's life-threatening injuries - abc13.com ...
Washington mom Sarah Fish is issuing a warning after her son almost died after taking on the popular &#39;duct tape challenge.&#39;

Resources last updated: 1/28/2016 11:33:04 PM