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. Set C standard in Qt Creator

Set C standard in Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 4.9k 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.
  • B Offline
    B Offline
    Bremenpl
    wrote on last edited by
    #1

    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_1980A 1 Reply Last reply
    1
    • B Bremenpl

      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.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      @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
      2
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        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_1980A 1 Reply Last reply
        2
        • fcarneyF fcarney

          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.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          fcarneyF 1 Reply Last reply
          3
          • aha_1980A aha_1980

            @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 ;)

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #5

            @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_1980A 1 Reply Last reply
            1
            • fcarneyF fcarney

              @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.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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
              0
              • B Offline
                B Offline
                Bremenpl
                wrote on last edited by
                #7

                @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_1980A 1 Reply Last reply
                0
                • B Bremenpl

                  @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
                  
                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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
                  1
                  • aha_1980A aha_1980

                    @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.

                    B Offline
                    B Offline
                    Bremenpl
                    wrote on last edited by
                    #9

                    @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
                    0
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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
                      1
                      • fcarneyF Offline
                        fcarneyF Offline
                        fcarney
                        wrote on last edited by
                        #11

                        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
                        3
                        • fcarneyF Offline
                          fcarneyF Offline
                          fcarney
                          wrote on last edited by
                          #12

                          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
                          1
                          • fcarneyF fcarney

                            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.

                            B Offline
                            B Offline
                            Bremenpl
                            wrote on last edited by
                            #13

                            @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
                            0
                            • fcarneyF Offline
                              fcarneyF Offline
                              fcarney
                              wrote on last edited by fcarney
                              #14

                              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
                              4
                              • fcarneyF 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++.

                                B Offline
                                B Offline
                                Bremenpl
                                wrote on last edited by
                                #15

                                @fcarney Understood, thank you.

                                lprzenioslo.zut.edu.pl

                                1 Reply Last reply
                                0

                                • Login

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