Compiler warnings

L

Lindsay

I'm getting some strange warnings when I compile:

pointer truncation from 'HMENU' to 'unsigned int'

The line in question is:
AppendMenu(hMenu,MF_STRING|MF_POPUP,UINT(hStyle),"Style");
(where hStyle is HMENU type)
This line is exactly the same as a line in another app I have but that one
doesn't give a warning.

Other warnings are:
pointer truncation from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to
'LONG'
conversion from 'LONG' to 'WNDPROC' of greater size
pointer truncation from 'WNDPROC' to 'LONG'

The lines in question are:
WNDPROC
_Wallpaper=(WNDPROC)SetWindowLong(hwnd,GWL_WNDPROC,(LONG)WallpaperProc);
SetWindowLong(GetDlgItem(hwndDlg,IDC_WALLPAPER),GWL_WNDPROC,(LONG)_Wallpaper);

Why should this be? My code works and the app functions as expected. I'm
sure I shouldn't get those warnings though.
 
J

John Harrison

Lindsay said:
I'm getting some strange warnings when I compile:

pointer truncation from 'HMENU' to 'unsigned int'

The line in question is:
AppendMenu(hMenu,MF_STRING|MF_POPUP,UINT(hStyle),"Style");
(where hStyle is HMENU type)
This line is exactly the same as a line in another app I have but that one
doesn't give a warning.

Other warnings are:
pointer truncation from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to
'LONG'
conversion from 'LONG' to 'WNDPROC' of greater size
pointer truncation from 'WNDPROC' to 'LONG'

The lines in question are:
WNDPROC
_Wallpaper=(WNDPROC)SetWindowLong(hwnd,GWL_WNDPROC,(LONG)WallpaperProc);
SetWindowLong(GetDlgItem(hwndDlg,IDC_WALLPAPER),GWL_WNDPROC,(LONG)_Wallpaper);

Why should this be? My code works and the app functions as expected. I'm
sure I shouldn't get those warnings though.

None of your code is standard C++ so is off topic here. Try asking on

Looks to me though that your warning are to do with VC++ gently
reminding you that pointers cannot safely be converted to integers or
vice versa. With 64-bit computing round the corner, the VC++ compiler
has got a lot more fussy about this issue.

john
 
V

Victor Bazarov

Lindsay said:
I'm getting some strange warnings when I compile:

pointer truncation from 'HMENU' to 'unsigned int'

Apparently pointers on your system are bigger than 'unsigned int'. I can
only speculate that you must be on Win64.
The line in question is:
AppendMenu(hMenu,MF_STRING|MF_POPUP,UINT(hStyle),"Style");
(where hStyle is HMENU type)
This line is exactly the same as a line in another app I have but that one
doesn't give a warning.

Are you sure you're building both apps for the same target platform?
Other warnings are:
pointer truncation from 'LRESULT (__stdcall *)(HWND,UINT,WPARAM,LPARAM)' to
'LONG'
conversion from 'LONG' to 'WNDPROC' of greater size
pointer truncation from 'WNDPROC' to 'LONG'

Again, sizeof(yourpointertypeabove) > sizeof(LONG).
The lines in question are:
WNDPROC
_Wallpaper=(WNDPROC)SetWindowLong(hwnd,GWL_WNDPROC,(LONG)WallpaperProc);
SetWindowLong(GetDlgItem(hwndDlg,IDC_WALLPAPER),GWL_WNDPROC,(LONG)_Wallpaper);

Why should this be? My code works and the app functions as expected. I'm
sure I shouldn't get those warnings though.

If you're sure, you need to complain to the maker of your compiler.

V
 
L

Lindsay

Victor Bazarov said:
Apparently pointers on your system are bigger than 'unsigned int'. I can
only speculate that you must be on Win64.

No. Both apps are Win32.
Are you sure you're building both apps for the same target platform?

Yes. They are both the same.
Again, sizeof(yourpointertypeabove) > sizeof(LONG).


If you're sure, you need to complain to the maker of your compiler.

How I would love to complain to MS. But it doesn't explain why one app is ok
and this one gives warnings.
 
A

Alf P. Steinbach

* Lindsay:
I'm getting some strange warnings when I compile:
pointer truncation from 'HMENU' to 'unsigned int'

Assuming Microsoft Visual C++:

That's probably because you are compiling with 64-bit compatibility
checking enabled. Then the compiler complains about things that won't
work somewhere in the future, plus a few things that will work in the
future but that it doesn't understand will work. That includes that it
may complain about e.g. giving a std::size_t to std::cout.

If you upgrade to version 8.x, assuming you haven't, then you may get
additional warnings on things like std::string::copy, because that
compiler team is really into warnings -- cry wolf, is their motto.
 
V

Victor Bazarov

Lindsay said:
[..]
How I would love to complain to MS. But it doesn't explain why one
app is ok and this one gives warnings.

Post to microsoft.public.vc.language -- that's where they talk VC++.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top