(-O3) What is optimization and what is g++'s default level?

-o3

I haven't used this flag and don't even know what it does, can someone explain what optimization is and what's the default optimization level in g++?
Last edited on
What the optimization really does is use various algorithms to analyze your code in order to convert to the smallest, fastest machine code, at the cost of longer compilation. The default is
-o0
, which means no optimization at all. In turn, the code will compile quite fast, but might create a more bloated program. https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html has more on this. Also, be warned that debugging with 2 or 3 can be a real challenge if you are not used to compiling at that level. If you want code that can be debugged while being optimized, use
-og
.
Last edited on
Topic archived. No new replies allowed.