by TeMPOraL · 12y ago · 0 comments
gcc -ansi -pedantic -Wall
At university I often had people coming to me and asking, "my program compiles correctly, but it keeps crashing / doing weird things; what did I do wrong?". I always said, "add '-ansi -pedantic -Wall' to the compile flags and come back to me when you cleared that wall of warnings down to nothing". Every single time the problem was directly or indirectly caused by the things that were in the warning messages.It's a shame that the default choice of GCC flags make this compiler pretty much useless for work.
The warnings are there to help you. You can choose to ignore them and that's fine, as long as you do it deliberately and with a damn good reason, not because you don't even know they're there.
gcc -std=c99 -Wall -Wextra -Werror
I'm not sure if -pedantic is still beneficial in that case. The gcc documentation had a list of every warning category, and which parameters enable each warning. This SO question was also interesting: http://stackoverflow.com/questions/11714827/how-to-turn-on-l... warning: C++ style comments are not allowed in ISO C90
warning: ISO C90 forbids mixed declarations and code
-Wall -Wextra gives me: warning: unused parameter ‘type’
For me, -Wextra is much more useful for finding messy code.Also —analyze to run the static analyzer: http://clang-analyzer.llvm.org
"Your compiler is trying to help you. Listen to it."
[1] http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Diagnostic-Pragm...
-Wall is enough to catch most relevant things, throw in -Wextra if you want overkill, not -ansi -pedantic.
I disagree (not "strongly" because your clarification in the next paragraph). That's only true if you don't know what are you doing.
That said, I am a big fan of gcc's -Wall since the late 90s, and I can tell you gcc has improved a lot since then.
(I say this because these days, I hear "C89" or "C90", "C99", or "C11". People who say "ANSI" get asked for clarification.)
Remember, many more of us use the compiler to build packages in the wild, we need it to be fairly permissive to hope to get things to build.