Weird C4244 warning message
-
Environment: Windows XP Professional 32-bit Visual Studio C++ Express Edition 8.0 SP2 Platform SDK Windows 2003 Server RC2 Project: C++, Windows 32-bit (x86), Debug, Unicode
Compiling... Dialog.cpp d:\lbm\bdm\dialog.cpp(43) : warning C4244: 'argument' : conversion from 'LONG' to 'LONG', possible loss of data [rest of compilation continues]
The code triggering the warning message:#ifdef \_WIN64 SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc)); #else SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG \_\_w64)(wcDlgInfo->m\_wcDlgProc)); #endif
Normally the line
SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc));
would suffice, but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit:
Compiling...
Dialog.cpp
d:\lbm\bdm\dialog.cpp(47) : warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of dataAny ideas why - LONG_PTR is considered "larger" than LONG on 32-bit x86, and - what means exactly the "conversion from LONG to LONG" warning message means, since _WIN64 is not defined? Many thanks, Cristian Amarie
-
Environment: Windows XP Professional 32-bit Visual Studio C++ Express Edition 8.0 SP2 Platform SDK Windows 2003 Server RC2 Project: C++, Windows 32-bit (x86), Debug, Unicode
Compiling... Dialog.cpp d:\lbm\bdm\dialog.cpp(43) : warning C4244: 'argument' : conversion from 'LONG' to 'LONG', possible loss of data [rest of compilation continues]
The code triggering the warning message:#ifdef \_WIN64 SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc)); #else SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG \_\_w64)(wcDlgInfo->m\_wcDlgProc)); #endif
Normally the line
SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc));
would suffice, but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit:
Compiling...
Dialog.cpp
d:\lbm\bdm\dialog.cpp(47) : warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of dataAny ideas why - LONG_PTR is considered "larger" than LONG on 32-bit x86, and - what means exactly the "conversion from LONG to LONG" warning message means, since _WIN64 is not defined? Many thanks, Cristian Amarie
I'm not sure about the error message, but...
Cristian Amarie wrote:
but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit
A LONG_PTR IS a 64-bit value in a 64-bit build. That's the whole reason for the newer type. It's a LONG but large enough to hold a pointer when pointers are 32-bit or 64-bit. I'm not sure what a "LONG __w64" is, but this line... SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG __w64)(wcDlgInfo->m_wcDlgProc)); ...won't work on a 32-bit build because pointers are 32-bit therefore you need to pass a 32-bit value. Sure, you can cast a 64-bit but it's going to be truncated to 32-bits. Mark
-
I'm not sure about the error message, but...
Cristian Amarie wrote:
but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit
A LONG_PTR IS a 64-bit value in a 64-bit build. That's the whole reason for the newer type. It's a LONG but large enough to hold a pointer when pointers are 32-bit or 64-bit. I'm not sure what a "LONG __w64" is, but this line... SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG __w64)(wcDlgInfo->m_wcDlgProc)); ...won't work on a 32-bit build because pointers are 32-bit therefore you need to pass a 32-bit value. Sure, you can cast a 64-bit but it's going to be truncated to 32-bits. Mark
[A LONG_PTR IS a 64-bit value in a 64-bit build] True, but as I stated in environment, is a 32-bit build. [I'm not sure what a "LONG __w64" is, but this line...] (Microsoft Specific) Lets you mark variables, such that when you compile with /Wp64 the compiler will report any warnings that would be reported if you were compiling with a 64-bit compiler. Is a "marker". About the last part of message, true, but (LONG __w64) was on #else part of #ifdef _WIN64.
-
[A LONG_PTR IS a 64-bit value in a 64-bit build] True, but as I stated in environment, is a 32-bit build. [I'm not sure what a "LONG __w64" is, but this line...] (Microsoft Specific) Lets you mark variables, such that when you compile with /Wp64 the compiler will report any warnings that would be reported if you were compiling with a 64-bit compiler. Is a "marker". About the last part of message, true, but (LONG __w64) was on #else part of #ifdef _WIN64.
Hmm What type is wcDlgInfo->m_wcDlgProc?
-
Hmm What type is wcDlgInfo->m_wcDlgProc?
typedef LRESULT (CALLBACK *WCDLGPROC)(HWND, UINT, WPARAM, LPARAM);
m_wcDlgProc is a pointer (to a window procedure).
-
Environment: Windows XP Professional 32-bit Visual Studio C++ Express Edition 8.0 SP2 Platform SDK Windows 2003 Server RC2 Project: C++, Windows 32-bit (x86), Debug, Unicode
Compiling... Dialog.cpp d:\lbm\bdm\dialog.cpp(43) : warning C4244: 'argument' : conversion from 'LONG' to 'LONG', possible loss of data [rest of compilation continues]
The code triggering the warning message:#ifdef \_WIN64 SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc)); #else SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG \_\_w64)(wcDlgInfo->m\_wcDlgProc)); #endif
Normally the line
SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG\_PTR)(wcDlgInfo->m\_wcDlgProc));
would suffice, but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit:
Compiling...
Dialog.cpp
d:\lbm\bdm\dialog.cpp(47) : warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of dataAny ideas why - LONG_PTR is considered "larger" than LONG on 32-bit x86, and - what means exactly the "conversion from LONG to LONG" warning message means, since _WIN64 is not defined? Many thanks, Cristian Amarie
Cristian Amarie wrote:
Normally the line SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG_PTR)(wcDlgInfo->m_wcDlgProc)); would suffice, but this also complains about the conversion of LONG_PTR to LONG, as if LONG_PTR is 64-bit:
I aggree with you. This should suffice. About warning, probably this could be issue with IDE.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
typedef LRESULT (CALLBACK *WCDLGPROC)(HWND, UINT, WPARAM, LPARAM);
m_wcDlgProc is a pointer (to a window procedure).
Yeah that's a good WTF :wtf: This...
::SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG)(LONG_PTR)(wcDlgInfo->m_wcDlgProc));
..."fixes" it on VS2003. I'd call that a bug, but every time I do, someone has a good reason for the behavior :)
-
Yeah that's a good WTF :wtf: This...
::SetWindowLongPtr(hdlg, DLGWINDOWEXTRA, (LONG)(LONG_PTR)(wcDlgInfo->m_wcDlgProc));
..."fixes" it on VS2003. I'd call that a bug, but every time I do, someone has a good reason for the behavior :)
Now that's a stretch (Dad to DeeDee - Dexter's Laboratory) :D