How to make gcc skip errors, but still print them.

Is it possible to get gcc to report errors but keep compiling them? Essentially, I'm trying to create a list of errors in a .c file, but gcc always ends on the first error. For some time I was looking for search queries, and this is not an obvious question that I can say.

+6
source share
3 answers

Modern versions of GCC will try to skip some errors where possible.

Let's say that the body foo(){... contains a const violation. The translation unit will not create an object file, but any worthy compiler will continue this error in bar(){...

Other errors cannot be recovered. If you miss any braces, there is no reasonable assumption that you can decide how to proceed.

0
source

The GCC ends when it cannot move on.

If the compiler encounters an error, it must guess what the correct code should be and try to follow. Effectively, this means that you always need to fix the first error and restart the compilation, as the rest will be meaningless.

Make sure you do not include -Wfatal-errors .

+2
source

From gcc online doc :

-fmax errors = n

Limits the maximum number of error messages to n, after which GCC is freed rather than trying to continue processing the source code. If n is 0 (default), then the number of error messages is unlimited. If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option.

0
source

Source: https://habr.com/ru/post/893783/


All Articles