參考語法:
http://gcc.gnu.org/onlinedocs/gcc/Funct ... agmas.html下面提供2個寫法,
其中寫法2會有warning出現,說這個語法在這個machine不支援,其實它的結果是正確的。
寫法1: 只針對1個function。
__attribute__((optimize("O0")))int add (int a, int b )
{
int x = a;
int y = b;
return x + y;
}
int main ()
{
int r = 1;
int a = r;
int b = r;
func ();
return 0;
}
寫法2:包含在裡面的code都不會被optimize。
注意!這個寫法不一定要以function為範圍,
可以任意選取一段code。#pragma GCC push_options
#pragma GCC optimize ("O0")int add (int a, int b )
{
int x = a;
int y = b;
return x + y;
}
#pragma GCC pop_optionsint main ()
{
int r = 1;
int a = r;
int b = r;
func ();
return 0;
}
#pragma GCC push_options
#pragma GCC pop_options
這2行是表示會先把原來的option push進去,
例如是-Os,
後面再把-Os pop回來,恢復原來的optimize設定。
關鍵字
optimize, optimization,最佳化,優化