eadmaster
eadmaster

Reputation: 1457

gcc print warnings without compile

I'd like gcc to do source code analysis for errors, but do not write any output files (similarly to what splint does). I've found this solution currently:

gcc -Wall -c source.c > NUL

Upvotes: 4

Views: 2465

Answers (2)

osgx
osgx

Reputation: 94415

There is -fsyntax-only option, which means exactly what you want:

"Check the code for syntax errors, but don’t do anything beyond that."

This option bit more portable between OSes than using /dev/null or NUL as output.

This option is also supported by clang C/C++/ObjC frontend, which is used with LLVM: clang-3.1 -fsyntax-only.

Update: But you should know that some warnings are generated not by syntax parser, but by internal compiler phases. For example, syntax parser can't detect full control flow (only optimizer will) and some warnings like "control reaches end of non-void function" will not be generated in -fsyntax-only option.

Upvotes: 9

dpp
dpp

Reputation: 1758

Well, you could redirect the output to /dev/null

gcc -o /dev/null ...

Upvotes: 5

Related Questions