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. How to fix compiler warning ?

How to fix compiler warning ?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
8 Posts 5 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.
  • A Offline
    A Offline
    Artem Moroz
    wrote on last edited by
    #1

    I have the following code: void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . . During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?

    T P A 3 Replies Last reply
    0
    • A Artem Moroz

      I have the following code: void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . . During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?

      T Offline
      T Offline
      Terry ONolley
      wrote on last edited by
      #2

      You could turn down the warning level :)



      1 Reply Last reply
      0
      • A Artem Moroz

        I have the following code: void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . . During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?

        P Offline
        P Offline
        Phil Hamer
        wrote on last edited by
        #3

        cast HIWORD result to WORD: *((WORD *)fixaddr) += (WORD)HIWORD(delta);

        D 1 Reply Last reply
        0
        • A Artem Moroz

          I have the following code: void* fixaddr; DWORD delta . . . *((WORD *)fixaddr) += HIWORD(delta); . . . During compilation I get the following error: warning C4244: '+=' : conversion from 'int' to 'unsigned short', possible loss of data Since I don't want any warnings appear in my code I wonder how to fix this ?

          A Offline
          A Offline
          Artem Moroz
          wrote on last edited by
          #4

          I have reduced warning level to 3, and this warning does not appear. Thanks for help!

          D 1 Reply Last reply
          0
          • A Artem Moroz

            I have reduced warning level to 3, and this warning does not appear. Thanks for help!

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Which does nothing but mask this and other potential problems. Leave the compiler warning level at 4 and fix the problem correctly. The compiler generates warnings/errors for a reason. If something wasn't suspect, there'd be no reason to warn you.


            Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

            S 1 Reply Last reply
            0
            • P Phil Hamer

              cast HIWORD result to WORD: *((WORD *)fixaddr) += (WORD)HIWORD(delta);

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Which makes little sense since the HIWORD() macro already casts its result to a WORD. The int that the compiler is complaining about is on the left of the += operator, not the right.


              Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

              P 1 Reply Last reply
              0
              • D David Crow

                Which does nothing but mask this and other potential problems. Leave the compiler warning level at 4 and fix the problem correctly. The compiler generates warnings/errors for a reason. If something wasn't suspect, there'd be no reason to warn you.


                Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                S Offline
                S Offline
                Steve S
                wrote on last edited by
                #7

                How refreshing! It's not just me that works that way, then :-D (The more of your replies I read, the more I wish you worked at the same place I do...) [fx: toadying mode off] Steve S

                1 Reply Last reply
                0
                • D David Crow

                  Which makes little sense since the HIWORD() macro already casts its result to a WORD. The int that the compiler is complaining about is on the left of the += operator, not the right.


                  Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                  P Offline
                  P Offline
                  Phil Hamer
                  wrote on last edited by
                  #8

                  I don't understand why, since the expression on the left IS a WORD. And we have no knowledge of this HIWORD macro; it maybe does not cast to a WORD.

                  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