Jamesits
Jamesits

Reputation: 642

C preprocessor: How can I disable #error macro?

I'm working on a C grammar analysis program. While running C preprocessor, there are some libraries which check the environment and use #error to stop compiling. How can I disable them, since I only need the preprocess step to finish?

Upvotes: 1

Views: 1290

Answers (2)

Peter
Peter

Reputation: 36607

If an #error preprocessor directive is being executed, that means preprocessing is done.

If the directive is conditional (e.g. an error only emitted if some set of conditions are met, such as in a #ifdef SOME_MACRO - #endif block) then the way to avoid it is to ensure the relevant conditions aren't true.

In the (extremely rare) situation that the #error is unconditional, then presumably the intent is to stop preprocessing immediately. Rather than disabling it, the solution is to avoid it (e.g. not #include the file which does that) not to disable it.

If you only want to run the preprocessor, then the presence of #error makes no difference. Most compilers either have the preprocessor as a separate program, or have an option (e.g. "gcc - E") that causes compilation to stop after the preprocessing phase.

Upvotes: 0

Adam Scroggin
Adam Scroggin

Reputation: 124

Why do you want to disable them? They are outputting an error and stopping compilation for a reason. The only way I know to disable them is to modify the source code and remove them.

Upvotes: 2

Related Questions