Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. not enough arguments for function-like macro invocation 'realloc'

not enough arguments for function-like macro invocation 'realloc'

Scheduled Pinned Locked Moved Unsolved General and Desktop
reallocincludemacro
10 Posts 5 Posters 2.5k Views
  • 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.
  • G Offline
    G Offline
    gragas
    wrote on 29 Mar 2021, 13:53 last edited by
    #1

    I have a problem, including some QtCore libraries in my project. I am using CMake and Visual Studio Qt 5.15. In my CMakeLists.txt I include QtCore like this:

    find_package(Qt5 REQUIRED COMPONENTS Core)
    
    target_link_libraries(${projectName} PRIVATE Qt5::Core)
    

    Then I add:

    #include <qstring.h>
    #include <qfile.h>
    

    in my code and some errors will show up:

    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(103): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(316): error C2059: syntax error: 'constant'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(327): note: see reference to class template instantiation 'QVector<T>' being compiled
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(411): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(420): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2988: unrecognizable template declaration/definition
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(700): error C2059: syntax error: 'constant'
    C:\qt\5.15.0\msvc2019_64\include\QtCore\qvector.h(1071): warning C4003: not enough arguments for function-like macro invocation 'realloc'
    

    This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.

    I tried deleting CMake cache, but with no result. This problem most probably has started since migrating from Visual Studio solution to CMake.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Mar 2021, 14:31 last edited by
      #2

      Your dev environment is wrong. Fix it. No Qt specfic problem I would guess. Create a simple main.cpp and see if it compiles when you include a Qt header. If not remove the Qt header and try to call realloc() directly by yourself. I would guess you get the same errors then.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kent-Dorfman
        wrote on 29 Mar 2021, 17:12 last edited by
        #3

        @gragas said in not enough arguments for function-like macro invocation 'realloc':

        Then I add:
        #include <qstring.h>
        #include <qfile.h>

        This error is probably issue of defining realloc two times, first in the qstring.h, then in the qfile.h.

        Because you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 29 Mar 2021, 17:36 last edited by
          #4

          @Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':

          you are not suppose to include the .h files. They are internal to the framework. You include the <QFile> and <QString> headers.

          But this can't lead to the compiler errors.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kent-Dorfman
            wrote on 29 Mar 2021, 20:32 last edited by
            #5

            I think it could, and very well may be. constant is obviously an undefined macro and the not enough arguements is probably a consequence of stringing together macro definitions where some are missing and are null or default empty strings.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 30 Mar 2021, 05:01 last edited by
              #6

              @Kent-Dorfman said in not enough arguments for function-like macro invocation 'realloc':

              I think it could, and very well may be.

              No, there is no difference when I include qcolor.h or QColor:

              > cat /usr/include/qt5/QtGui/QColor
              #include "qcolor.h"
              

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • G Offline
                G Offline
                gragas
                wrote on 31 Mar 2021, 11:21 last edited by
                #7

                The reason this happened was, redefinition of realloc keyword. I had to do push/pop realloc macro for new keyword as well. I Think this issue was solved in Qt 6, but thanks anyway. Refference: https://bugreports.qt.io/browse/QTBUG-40575.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 31 Mar 2021, 19:33 last edited by
                  #8

                  Hi,

                  Adding link to the corresponding code review.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    KIMI2023
                    wrote on 18 Jan 2023, 06:28 last edited by
                    #9

                    I met the same question, (Debug version NG, release version OK)
                    Solution:
                    find file[crtdbg.h]:D:\Windows Kits\10\Include\10.0.19041.0\ucrt\crtdbg.h
                    to commet follow:
                    //#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, FILE, LINE)

                    S 1 Reply Last reply 18 Jan 2023, 07:44
                    0
                    • K KIMI2023
                      18 Jan 2023, 06:28

                      I met the same question, (Debug version NG, release version OK)
                      Solution:
                      find file[crtdbg.h]:D:\Windows Kits\10\Include\10.0.19041.0\ucrt\crtdbg.h
                      to commet follow:
                      //#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, FILE, LINE)

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 18 Jan 2023, 07:44 last edited by
                      #10

                      Hi and welcome to devnet,
                      @KIMI2023 said in not enough arguments for function-like macro invocation 'realloc':

                      I met the same question, (Debug version NG, release version OK)
                      Solution:
                      find file[crtdbg.h]:D:\Windows Kits\10\Include\10.0.19041.0\ucrt\crtdbg.h
                      to commet follow:
                      //#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, FILE, LINE)

                      Changing a file in the Windows development framework is not the correct way to handle that situation. As was done in the patch I linked, fixing the code is.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved