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?
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(); }
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 targetand#pragma GCC optimizeto use the default switches as specified on the command line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With