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. abs() function is wierd

abs() function is wierd

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++visual-studio
7 Posts 4 Posters 1 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
    Adrian Metcalfe
    wrote on last edited by
    #1

    Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!

    D C A T 4 Replies Last reply
    0
    • A Adrian Metcalfe

      Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!

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

      Are the compiler settings for each exactly the same?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      A 1 Reply Last reply
      0
      • A Adrian Metcalfe

        Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        From the MSDN website:

        C++ allows overloading, so you can call overloads of abs. In a C program, abs always takes and returns an int.

        Is that answering your question ? Maybe your second program is compiled as pure C program ?

        A 1 Reply Last reply
        0
        • D David Crow

          Are the compiler settings for each exactly the same?


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          A Offline
          A Offline
          Adrian Metcalfe
          wrote on last edited by
          #4

          Yes, the compiler settings are exactly the same for both apps. Wierd eh ? Users. Can't live with 'em, can't kill em!

          1 Reply Last reply
          0
          • C Cedric Moonen

            From the MSDN website:

            C++ allows overloading, so you can call overloads of abs. In a C program, abs always takes and returns an int.

            Is that answering your question ? Maybe your second program is compiled as pure C program ?

            A Offline
            A Offline
            Adrian Metcalfe
            wrote on last edited by
            #5

            I agree, I have checked that abs() has not been overloaded anywhere else in the program, it has not. Wierd eh ? Both programs are compiled as C++ Users. Can't live with 'em, can't kill em! -- modified at 9:04 Thursday 22nd September, 2005

            1 Reply Last reply
            0
            • A Adrian Metcalfe

              Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!

              A Offline
              A Offline
              Adrian Metcalfe
              wrote on last edited by
              #6

              Problem solved ! A co-worker found that was included in StdAfx.h When commented out, both apps perform the same way. Cheers everybody Users. Can't live with 'em, can't kill em!

              1 Reply Last reply
              0
              • A Adrian Metcalfe

                Anybody ever seen this: Using VS.NET 2003 to compile C++ code. App 1 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; App 2 double freq = 6; double newFreq = abs( freq + 0.5 ) + 4; When compiled App 1 = 0 errors, o warnings App 2 = Warning C4244 conversion from 'double' to 'int', possible loss of data Strange ? But wait there is more ! App 1 Value of newFreq = 10.5 App 2 Value of newFreq = 10 Why does 'App 1' not produce the warning and a different answer ? I am confused. Users. Can't live with 'em, can't kill em!

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                even if it is fixed, did you have a look at ::abs() and ::fabs() ?


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                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