Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Weird C4244 warning message

Weird C4244 warning message

Scheduled Pinned Locked Moved C / C++ / MFC
c++csharpvisual-studiosysadmindebugging
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cristian Amarie
    wrote on last edited by
    #1

    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 data

    Any 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

    M P 2 Replies Last reply
    0
    • C 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 data

      Any 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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        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

        C Offline
        C Offline
        Cristian Amarie
        wrote on last edited by
        #3

        [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.

        M 1 Reply Last reply
        0
        • C Cristian Amarie

          [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.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Hmm What type is wcDlgInfo->m_wcDlgProc?

          C 1 Reply Last reply
          0
          • M Mark Salsbery

            Hmm What type is wcDlgInfo->m_wcDlgProc?

            C Offline
            C Offline
            Cristian Amarie
            wrote on last edited by
            #5

            typedef LRESULT (CALLBACK *WCDLGPROC)(HWND, UINT, WPARAM, LPARAM);

            m_wcDlgProc is a pointer (to a window procedure).

            M 1 Reply Last reply
            0
            • C 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 data

              Any 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

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              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[][^]

              1 Reply Last reply
              0
              • C Cristian Amarie

                typedef LRESULT (CALLBACK *WCDLGPROC)(HWND, UINT, WPARAM, LPARAM);

                m_wcDlgProc is a pointer (to a window procedure).

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                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 :)

                C 1 Reply Last reply
                0
                • M Mark Salsbery

                  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 :)

                  C Offline
                  C Offline
                  Cristian Amarie
                  wrote on last edited by
                  #8

                  Now that's a stretch (Dad to DeeDee - Dexter's Laboratory) :D

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups