0
votes

Is there a way to make GCC's preprocessor stop when it finds a #error, when running it with option -E?

For instance, in the following program:

#error STOP HERE
int main() {
  return 0;
}

Running gcc on this program results in an interrupted compilation at line 1, but running gcc -E outputs the same line, and then continues with preprocessing.

Note: my question is similar to GCC #pragma to stop compilation, but concerning the -E flag, so maybe both should be merged?

1

1 Answers

1
votes

The short answer is no. Processor directives (e.g. #error ) are used to give commands to the compiler. By using the -E option the compiler never runs, so it doesn't have a reason to stop. The -E flag is design to print all the code that gets compiled with your program without actually compiling.