What does '#pragma GCC optimize ("O3")' mean?

Madhu R picture Madhu R · Nov 10, 2017 · Viewed 17.2k times · Source

I came through this line in project source code written before a function. I want to know, what is the use of it ?

#pragma GCC optimize ("O3")

void somefunction()
{
  ....
}

Requesting to explain every argument used in the directive.

Thanks and Regards.

Answer

paxdiablo picture paxdiablo · Nov 10, 2017

Pragmas are implementation specific but, in this case (gcc), it sets the optimisation level to 3 (high), similar in effect to using -O3 on the command line.

Details on optimisation levels for gcc, and the individual flags that get set in response, can be found here.