Set C standard in Qt Creator
-
wrote on 19 Mar 2019, 13:06 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. -
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.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.
-
wrote on 19 Mar 2019, 15:40 last edited by
Perhaps this might explain it:
https://stackoverflow.com/questions/2223541/why-cant-i-use-style-comments-in-my-c-codeIts 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.
-
Perhaps this might explain it:
https://stackoverflow.com/questions/2223541/why-cant-i-use-style-comments-in-my-c-codeIts 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.
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 ;)
-
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 ;)
wrote on 19 Mar 2019, 20:13 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.
-
@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.
@fcarney said in Set C standard in Qt Creator:
I remember when searching used to be an art. Maybe it still is.
+1
-
wrote on 20 Mar 2019, 10:17 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
-
@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
@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.
-
@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.
wrote on 20 Mar 2019, 13:24 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. -
@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.
-
wrote on 20 Mar 2019, 14:16 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? -
wrote on 20 Mar 2019, 14:20 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.
-
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.
wrote on 20 Mar 2019, 14:24 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?
-
wrote on 20 Mar 2019, 14:26 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++. -
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++.
1/15