Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Set C standard in Qt Creator

    General and Desktop
    4
    15
    3660
    Loading More Posts
    • 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.
    • B
      Bremenpl last edited by

      Hello there,
      What is the proper way of setting C89 standard in the *.pro file for a C project in Qt Creator? Currently this setting is added:

      CONFIG += -std=c89
      QMAKE_CFLAGS += -std=c89
      

      But I can still compile C99+ specific code, like // block comments or in for variable initialization.
      I would appreciate all help.

      lprzenioslo.zut.edu.pl

      aha_1980 1 Reply Last reply Reply Quote 1
      • aha_1980
        aha_1980 Lifetime Qt Champion @Bremenpl last edited by aha_1980

        @Bremenpl

        Which operating system and compiler is this? And which Qt version?

        Edit: also check the compile log which flags are passed to the C compiler.

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 2
        • fcarney
          fcarney last edited by

          Perhaps this might explain it:
          https://stackoverflow.com/questions/2223541/why-cant-i-use-style-comments-in-my-c-code

          Its funny, in Google search if you put in -std=c89 it will try and eliminate std=c89 from the search results. So search on std=c89 yielded better results.

          C++ is a perfectly valid school of magic.

          aha_1980 1 Reply Last reply Reply Quote 2
          • aha_1980
            aha_1980 Lifetime Qt Champion @fcarney last edited by

            @fcarney

            Its funny, in Google search if you put in -std=c89 it will try and eliminate std=c89 from the search results. So search on std=c89 yielded better results.

            Thats because minus is the logical not in Google, and has been forever ;)

            Qt has to stay free or it will die.

            fcarney 1 Reply Last reply Reply Quote 3
            • fcarney
              fcarney @aha_1980 last edited by

              @aha_1980 said in Set C standard in Qt Creator:

              Thats because minus is the logical not in Google, and has been forever ;)

              Yeah, I had forgotten the "good old days" of +/- and using quotes and things to help narrow searches. I remember when searching used to be an art. Maybe it still is.

              C++ is a perfectly valid school of magic.

              aha_1980 1 Reply Last reply Reply Quote 1
              • aha_1980
                aha_1980 Lifetime Qt Champion @fcarney last edited by

                @fcarney said in Set C standard in Qt Creator:

                I remember when searching used to be an art. Maybe it still is.

                +1

                Qt has to stay free or it will die.

                1 Reply Last reply Reply Quote 0
                • B
                  Bremenpl last edited by

                  @aha_1980 Hi, thanks for answer.
                  The intended OS is both Windows (mingw C compiler) and Linux (GCC). Qt version is 5.11.1.

                  Here is the compiler output:

                  gcc -c -fno-keep-inline-dllexport -std=c89 -g -Wall -W -Wextra -DUNICODE -D_UNICODE -DWIN32 -DNTM_LIB_LIBRARY -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -I..\ntm\trunk\libntm -I. -I..\..\..\..\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o debug\calc.o ..\ntm\trunk\libntm\calc\calc.c
                  

                  lprzenioslo.zut.edu.pl

                  aha_1980 1 Reply Last reply Reply Quote 0
                  • aha_1980
                    aha_1980 Lifetime Qt Champion @Bremenpl last edited by

                    @Bremenpl A short search gave https://stackoverflow.com/questions/2270899/c89-vs-c99-gcc-compiler

                    which states:

                    In theory, there should be one difference. Using "//" to demark a comment isn't part of C89, so if it enforced the C89 rules correctly, that would produce a compiler error (with -ansi -pedantic, it might do that, but I don't remember for sure).

                    Looks like the explanation for your problem.

                    Qt has to stay free or it will die.

                    B 1 Reply Last reply Reply Quote 1
                    • B
                      Bremenpl @aha_1980 last edited by

                      @aha_1980 I think you guys misunderstood me, or I didn't state the question properly.
                      I am OK with the fact that // comments are not allowed in C89. Futhermore, I want to use the C89 standard in this project. The thing is, I dont know how to instruct the Qt creator, using the *.pro file, to use C89 for compiling. And I know that it doesnt work, since I am able to do // comments and for loops with initialization.

                      lprzenioslo.zut.edu.pl

                      1 Reply Last reply Reply Quote 0
                      • Christian Ehrlicher
                        Christian Ehrlicher Lifetime Qt Champion last edited by

                        @Bremenpl said in Set C standard in Qt Creator:

                        -std=c89

                        If this is in the compiler output as you wrote above then qtcreator / qmake isn't the one to blame.

                        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 Reply Quote 1
                        • fcarney
                          fcarney last edited by

                          I just tried this with Qt 5.12.0, gcc, Linux and a standard C project through Qt Creator.
                          I put this in my pro file:

                          QMAKE_CFLAGS += -std=c89
                          

                          So my pro looks like this:

                          TEMPLATE = app
                          CONFIG += console
                          CONFIG -= app_bundle
                          CONFIG -= qt
                          QMAKE_CFLAGS += -std=c89
                          
                          SOURCES += \
                                  main.c
                          

                          My C source looks like this:

                          #include <stdio.h>
                          
                          // this is a comment
                          int main()
                          {
                              printf("Hello World!\n");
                              return 0;
                          }
                          

                          This will not compile and throws this error:

                          /home/fcarney/Documents/programming/test/testcstandards/main.c:3: error: C++ style comments are not allowed in ISO C90
                           // this is a comment
                           ^
                          

                          The Qt creator IDE shows this error:

                          /home/fcarney/Documents/programming/test/testcstandards/main.c:3: warning: // comments are not allowed in this language
                          

                          Is it possible your project is a C++ project?
                          What is the extension of your file? .c .cpp ?
                          What compiler are you using? MSVC, gcc, Mingw?

                          C++ is a perfectly valid school of magic.

                          1 Reply Last reply Reply Quote 3
                          • fcarney
                            fcarney last edited by

                            I just repeated the test on Windows 10 Pro, Mingw64, Qt 5.12.1 with an similarly generated C project. I get the same result as the Linux test.

                            C++ is a perfectly valid school of magic.

                            B 1 Reply Last reply Reply Quote 1
                            • B
                              Bremenpl @fcarney last edited by

                              @fcarney Thanks for answer, I rewrote the *.pro file carefully and it indeed works now. Had to had some faulty flags maybe. Thank you for help.

                              As a side note, is it even possible to create a plain C (not C++) project in Qt creator?

                              lprzenioslo.zut.edu.pl

                              1 Reply Last reply Reply Quote 0
                              • fcarney
                                fcarney last edited by fcarney

                                Yes:
                                File -> New File or Project -> Non-Qt Project -> Plain C Application
                                That is how I created my test project. You will have to add the CFLAG.

                                Edit:
                                Do you mean using Qt widgets and the like? Probably not as all the graphical stuff seems to be heavily C++.

                                C++ is a perfectly valid school of magic.

                                B 1 Reply Last reply Reply Quote 4
                                • B
                                  Bremenpl @fcarney last edited by

                                  @fcarney Understood, thank you.

                                  lprzenioslo.zut.edu.pl

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post