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. cmath.h compile error

cmath.h compile error

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
14 Posts 6 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.
  • H Haakon S

    I don't understand that. It is a compile error in a core library file. I am not allowed to change it. Why would the calling function have anything to say?

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #5

    Quote:

    Why would the calling function have anything to say? Quote Selected Text

    With very high probability the calling code is wrong (possibly making incorrect assumptions on the called function, it passes the wrong type). Maybe a previous implementation of the library had relaxed checks on calling code correctness.

    "In testa che avete, Signor di Ceprano?" -- Rigoletto

    In testa che avete, signor di Ceprano?

    1 Reply Last reply
    0
    • Greg UtasG Greg Utas

      Use your development environment (VS or whatever) to check that there is a #define for each the following: NODISCARD _Check_return_ _In_ _CSTD And if you're using C instead of C++, noexcept could be the problem. But I can't say, because I only write C++. EDIT: :doh: type 'int' unexpected suggests that the caller is passing an int, not a float.

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      H Offline
      H Offline
      Haakon S
      wrote on last edited by
      #6

      There are plenty of _Check_return_ statements that work. If there is something wrong with the calling function, I should get a compile error when compiling the cpp file where the function is called? This is an error from inside the include file cmath.h. Three errors reported, underscore is the highlighted error indication. Line 210 _NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ { return _CSTD roundf(_Xx); } Line 446 _NODISCARD _Check_return_ inline long double round(_In_ long double _Xx) noexcept /* strengthened */ { return _CSTD roundl(_Xx); } Line 663 _GENERIC_MATH1(round) It seems I am not allowed to alter any include file, so I can not experiment with commenting the functions out, etc.

      Greg UtasG 1 Reply Last reply
      0
      • H Haakon S

        I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:

        NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
        return _CSTD roundf(_Xx);
        }

        With first round statement highlighted I get this message: C2062 type'int' unexpected

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

        I would be inclined to look at the preprocessor output to see what all of those non-standard "types" are.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        1 Reply Last reply
        0
        • H Haakon S

          There are plenty of _Check_return_ statements that work. If there is something wrong with the calling function, I should get a compile error when compiling the cpp file where the function is called? This is an error from inside the include file cmath.h. Three errors reported, underscore is the highlighted error indication. Line 210 _NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ { return _CSTD roundf(_Xx); } Line 446 _NODISCARD _Check_return_ inline long double round(_In_ long double _Xx) noexcept /* strengthened */ { return _CSTD roundl(_Xx); } Line 663 _GENERIC_MATH1(round) It seems I am not allowed to alter any include file, so I can not experiment with commenting the functions out, etc.

          Greg UtasG Offline
          Greg UtasG Offline
          Greg Utas
          wrote on last edited by
          #8

          Check if round is also defined somewhere else, and check that _GENERIC_MATH1 is actually defined. Beyond that, I don't know.

          Robust Services Core | Software Techniques for Lemmings | Articles
          The fox knows many things, but the hedgehog knows one big thing.

          <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
          <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

          1 Reply Last reply
          0
          • H Haakon S

            I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:

            NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
            return _CSTD roundf(_Xx);
            }

            With first round statement highlighted I get this message: C2062 type'int' unexpected

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            Hi, I am going to point out that you are almost certainly looking at the wrong code location. The C2062 error usually really does mean the 3 letters 'int' were unexpected while parsing the code. Look around for an int that is declared wrong.

            1 Reply Last reply
            0
            • H Haakon S

              I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:

              NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
              return _CSTD roundf(_Xx);
              }

              With first round statement highlighted I get this message: C2062 type'int' unexpected

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              Is that the full text of the error message? Also what are the few lines either side of that definition?

              1 Reply Last reply
              0
              • H Haakon S

                I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:

                NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
                return _CSTD roundf(_Xx);
                }

                With first round statement highlighted I get this message: C2062 type'int' unexpected

                D Offline
                D Offline
                Daniel Pfeffer
                wrote on last edited by
                #11

                Your compiler should have an option to send the output of the preprocessor into a file. Using Visual C/C++, this option is /P, and the output file has an extension of .i . Run your code through this, and look for cmath.h in the .i file. Then look for the definition of the round() function. You will see what the compiler thinks the round() function is, and your problem should then be obvious. :)

                Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                1 Reply Last reply
                0
                • H Haakon S

                  I am compiling some old legacy code with MFC. For this line in cmath.h I get an error:

                  NODISCARD _Check_return_ inline float round(_In_ float _Xx) noexcept /* strengthened */ {
                  return _CSTD roundf(_Xx);
                  }

                  With first round statement highlighted I get this message: C2062 type'int' unexpected

                  H Offline
                  H Offline
                  Haakon S
                  wrote on last edited by
                  #12

                  Hi and thanks for all help. When I put

                  #include

                  right under #include stdafx.h it compiled. Don't ask me exactly why. It may be a conflict between math.h and cmath that was solved in this way. Regards, Haakon S.

                  L 1 Reply Last reply
                  0
                  • H Haakon S

                    Hi and thanks for all help. When I put

                    #include

                    right under #include stdafx.h it compiled. Don't ask me exactly why. It may be a conflict between math.h and cmath that was solved in this way. Regards, Haakon S.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #13

                    So... You said that your compiler gave you an error in cmath.h

                    Haakon S. wrote:

                    For this line in cmath.h I get an error:

                    Which you solved... "by including cmath.h" :confused:

                    H 1 Reply Last reply
                    0
                    • L Lost User

                      So... You said that your compiler gave you an error in cmath.h

                      Haakon S. wrote:

                      For this line in cmath.h I get an error:

                      Which you solved... "by including cmath.h" :confused:

                      H Offline
                      H Offline
                      Haakon S
                      wrote on last edited by
                      #14

                      I honestly don't know what is going on. Some files had #include . Removing this did't help. It reported error in cmath anyway. When googling "cmath error c2062" I see that others have had the same problem. Anyway, it seems that I have found the solution.

                      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