chrisvarnz
chrisvarnz

Reputation: 457

How to get gcc to skip errors, but still output them.

is it possible to force gcc to report errors, but keep compiling past them? Essentially I'm trying to generate a list of errors in a .c file, but gcc always terminates at the first error. I've been googling for a while and this isn't an obvious one to solve from what I can tell.

Upvotes: 6

Views: 7769

Answers (3)

user1823890
user1823890

Reputation: 744

From gcc online doc:

-fmax-errors=n

Limits the maximum number of error messages to n, at which point GCC bails out rather than attempting to continue processing the source code. If n is 0 (the default), there is no limit on the number of error messages produced. If -Wfatal-errors is also specified, then -Wfatal-errors takes precedence over this option.

Upvotes: 0

spraff
spraff

Reputation: 33395

Up-to-date versions of GCC will attempt to skip certain errors where possible.

Say the body of foo(){... contains a const-violation. The translation unit will not produce an object file but any decent compiler will continue past this error into bar(){...

Other errors are unrecoverable. If you miss out some curly braces there's no reasonable guess that can be mades as to how to proceed.

Upvotes: 1

Šimon Tóth
Šimon Tóth

Reputation: 36433

GCC terminates when it can't go further.

If a compiler encounters an error, it has to guess what the correct code should be and try to follow. Effectively that means that you always need to fix the first error and re-run the compilations, since the rest will be nonsense.

Make sure that you haven't turned -Wfatal-errors on.

Upvotes: 2

Related Questions