C预处理器:如何禁用#error宏?

时间:2021-05-07 18:57:58

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?

我正在研究C语法分析程序。在运行C预处理器时,有一些库检查环境并使用#error停止编译。如何禁用它们,因为我只需要预处理步骤即可完成?

2 个解决方案

#1


2  

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.

你为什么要禁用它们?他们输出错误并因某种原因停止编译。我知道禁用它们的唯一方法是修改源代码并删除它们。

#2


0  

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

如果正在执行#error预处理程序指令,则表示已完成预处理。

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.

如果指令是有条件的(例如,只有满足某些条件时才会发出错误,例如在#ifdef SOME_MACRO - #endif块中),那么避免它的方法是确保相关条件不成立。

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.

在(非常罕见)#error是无条件的情况下,可能意图是立即停止预处理。而不是禁用它,解决方案是避免它(例如,不#include执行该操作的文件)不禁用它。

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.

如果你只想运行预处理器,那么#error的存在没有区别。大多数编译器要么将预处理器作为单独的程序,要么具有选项(例如“gcc -E”),这会导致编译在预处理阶段后停止。

#1


2  

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.

你为什么要禁用它们?他们输出错误并因某种原因停止编译。我知道禁用它们的唯一方法是修改源代码并删除它们。

#2


0  

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

如果正在执行#error预处理程序指令,则表示已完成预处理。

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.

如果指令是有条件的(例如,只有满足某些条件时才会发出错误,例如在#ifdef SOME_MACRO - #endif块中),那么避免它的方法是确保相关条件不成立。

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.

在(非常罕见)#error是无条件的情况下,可能意图是立即停止预处理。而不是禁用它,解决方案是避免它(例如,不#include执行该操作的文件)不禁用它。

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.

如果你只想运行预处理器,那么#error的存在没有区别。大多数编译器要么将预处理器作为单独的程序,要么具有选项(例如“gcc -E”),这会导致编译在预处理阶段后停止。