Home > database >  GCC #pragma or command options
GCC #pragma or command options

Time:11-24

If the compiler has some command-line flags and the code has some pragmas that are incompatible with those flags, which one will be used?

To be clearer: I am compiling with g -g -O2 -std=gnu 17 -static {files} – GCC version g (Ubuntu 9.3.0-10ubuntu2) 9.3.0.

If I write in my code #pragma GCC optimize("Ofast"), will the final code be compiled with -O2 or with -Ofast?

CodePudding user response:

That depends on if it's above or below the pragma.

void this_will_be_compiled_with_O2() { stuff(); }

#pragma GCC optimize("Ofast")

void this_will_be_compiled_with_Ofast() { stuff(); }

CodePudding user response:

Although not explicitly mentioned in the documentation, the description of the #pragma GCC reset_options directive implies that any #pragma GCC optimize directive will override the command line option(s):

#pragma GCC reset_options

    This pragma clears the current #pragma GCC target and #pragma GCC optimize to use the default switches as specified on the command line.

  • Related