I’m not positive, because I am far from an expert on GCC, but I believe you can (or at least should) only select one optimization level at a time. There are a number of different things that could be done to optimize a program. In GCC, these are controlled by individual flags, each of which controls a specific optimization action. I believe that the different levels end up setting different combinations of optimization flags. In the version I use, I can set a level, and I can also control some other optimization flags from the IDE. If you select more than one level at a time, you may end up with a combination of flags.

You could try setting various combinations of levels, and then look at what flags actually get set.

Keep in mind that optimizing for one attribute may be detrimental to another. In general, with any compiler, going from no optimization to the first level of optimization will result in an increase in speed and a decrease in size. This is because a bunch of unnecessary stuff gets thrown out. When you start optimizing beyond that, you may start trading off speed for size. Optimization can also play havoc with debugging, particularly single stepping. And some optimizations may mess with others. (That is, “Some combinations of flags may result in code that does not work as expected!”)

I would recommend that you come up with some sort of benchmark so you have an idea of the effect of different optimizations. Size is easy, you can just look at the resulting code size. Speed is a bit more challenging. You may not even need any speed optimization, but only you can make that determination.

You may want to get a copy of the book “An Introduction to GCC for the GNU Compiler gcc and g++”, written by Brian Gough. Published by Network Theory Limited ISBN 0-9541617-9-3

This question has already been answered. Start a new discussion instead.