日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GCC 编译时优化某一个或几个函数或者不优化某一个或几个函数

發布時間:2024/4/13 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GCC 编译时优化某一个或几个函数或者不优化某一个或几个函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 有的時候我們會有這樣的需求:不想讓編譯器優化某一個或幾個函數、針對某一個或幾個函數做設置特殊的優化等級。
  • 以下有三種方法:
  • __attribute((optimize(“STRING”)))的例子,fun1函數使用O0優化級別,fun2函數使用O2優化級別。
  • // 首先用__attribute__聲明函數 int fun1(int a, int b) __attribute__((optimize("O0"))); // 然后再定義函數,聲明和定義必須分開,否則編譯錯誤 int fun1(int a, int b) {printf("fun1 is (optimize(\"O0\")"); } int fun2(int a, int b) __attribute__((optimize("O2"))); int fun2(int a, int b) {printf("fun2 is (optimize(\"O2\")"); }
  • pragma GCC optimize (“string”…)的例子,pragma語句下面的fun4和fun5函數都使用O3優化級別。pragma語句上面的fun3函數使用命令行指定的優化級別。
  • int fun3(int a, int b) {printf("fun3 is optimize default"); } #pragma GCC optimize ("O3") int fun4(int a, int b) {printf("fun4 is (optimize(\"O3\")"); } int fun5(int a, int b) {printf("fun5 is (optimize(\"O3\")"); }
  • #pragma GCC push_options #pragma GCC pop_options These pragmas maintain a stack of the current target and optimization options. It is intended for include files where you temporarily want to switch to using a different `#pragma GCC target' or `#pragma GCC optimize' and then to pop back to the previous options. //這些實用程序保留了當前目標和優化選項的堆棧。 它用于包含文件,在這些文件中,您臨時要切換到使用其他“ #pragma GCC目標”或“ #pragma GCC優化”,然后彈出回到先前的選項。 The `#pragma GCC push_options' and `#pragma GCC pop_options' pragmas are not implemented in GCC versions earlier than 4.4.#pragma GCC reset_options This pragma clears the current #pragma GCC target and #pragma GCC optimize to use the default switches as specified on the command line. //該編譯指示清除當前的#pragma GCC目標,并且#pragma GCC優化以使用命令行上指定的默認開關。 The `#pragma GCC reset_options' pragma is not implemented in GCC versions earlier than 4.4.
  • #pragma GCC optimize ("string"...) This pragma allows you to set global optimization options for functions defined later in the source file. One or more strings can be specified. Each function that is defined after this point is as if attribute((optimize("STRING"))) was specified for that function. The parenthesis around the options is optional. See Section 6.30 [Function Attributes], page 376, for more information about the optimize attribute and the attribute syntax. The ‘#pragma GCC optimize’ pragma is not implemented in GCC versions earlier than 4.4 ? #pragma GCC push_options #pragma GCC optimize ("O3")//your code optimize ("O3") specially#pragma GCC pop_options

總結

以上是生活随笔為你收集整理的GCC 编译时优化某一个或几个函数或者不优化某一个或几个函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。