GCC 指定编译优化选项(optimize)

GCC offers two methods to selectively tweak the optimization level: at the file level, or at the function level.

If you want to set optimization level for a single function, you can use the optimize function attribute:

void attribute((optimize(“O3”))) fast_function(void) {
// …

For a whole file, you can use the optimize pragma:

#pragma GCC push_options
#pragma GCC optimize ("O3")

 * Code that needs optimizing

#pragma GCC pop_options

Note that the push_options and pop_options pragmas are needed to make sure the rest of the file is compiled with the regular options.