Reputation: 41
I was thinking the other day and this came to mind. I heard that -g turn off optimizations for debugging, but -O0 does turn off all optimizations, right? I am just wondering.
Upvotes: 0
Views: 330
Reputation: 58493
I heard that -g turn off optimizations for debugging
That's not true. -g
only tells the compiler to include debug information in the object file; it has no effect on the code that is actually generated, and it can be used in combination with any optimization option you like. It will be more useful when used with -O0
or -Og
, as higher optimization levels can change the code in ways that makes it hard to use a debugger, but this is not mandatory.
but -O0 does turn off all optimizations, right?
Yes, that is correct; at least, all optimizations that can be turned off at all. (As JcWasmx86 points out, there are some "optimizations" that are done even at -O0
, but you can expect them to be transformations that won't require significant compile time or dramatically change the structure of the generated code.)
Upvotes: 1