• 有的时候我们会有这样的需求:不想让编译器优化某一个或几个函数、针对某一个或几个函数做设置特殊的优化等级。
  • 以下有三种方法:
  • __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 编译时优化某一个或几个函数或者不优化某一个或几个函数相关推荐

  1. linux编译动态库未定义,GCC链接库的一个坑:动态库存在却提示未定义动态库的函数...

    背景 在GCC中已经指定链接库,然而编译时却提示动态库函数未定义! 测试出现的错误提示如下: [GMPY@13:48 tmp]$gcc -o test -L. -lmylib test.c /tmp/ ...

  2. c语言中包含math.h的时用gcc编译要加-lm参数

    c语言中包含math.h时,用gcc编译时要-lm参数: 如以下的程序sqrt.c,编译:gcc sqrt.c -o sqrt -lm /*sqrt.c*/ /*在0到十万里找出一个加上100且加上1 ...

  3. GCC编译、链接、运行时库查找顺序(最真实可信)

    参考了不少资料,其中最靠谱是这个:http://www.mingw.org/wiki/librarypathhowto 和http://www.kaizou.org/2015/01/linux-lib ...

  4. gcc编译流程及中间表示层RTL的探索

    gcc编译流程及中间表示层RTL的探索收藏 新一篇: 解读VC++编程中的文件操作API和CFile类 | 旧一篇: Effective Item21 尽可能使用const 内容摘要 本文将以 C 语 ...

  5. GCC编译警告选项的学习

    GCC有很多的编译选项,警告选项:指定头文件.库路径:优化选项.本文针整理一下GCC的警告选项,主要依据http://gcc.gnu.org/onlinedocs/gcc/Warning-Option ...

  6. GCC编译过程与动态链接库和静态链接库

    1. 库的介绍 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常. 本质上来说库是一种可执行代码的二进制形式,可 ...

  7. gcc编译可执行文件和cmake编译可执行文件

    gcc编译 gcc的下载(下载mingw,里面包含gcc) 下载安装MinGW-w64详细步骤(c/c++的编译器gcc的windows版,win10真实可用) gcc编译可执行文件 由源码转换为可执 ...

  8. linux(ubuntu 10.10) 64位系统 gcc编译(c)成32位(静态)可执行应用程序的方法

    在ubuntu 64位系统里编写好C程序,用GCC直接编译的话是64位的可执行文件, 如果拿到linux 32位的操作系统上是不能直接运行的. 所以可以在GCC 编译时 加入-m32 参数. 例如: ...

  9. g linux 未定义的引用_【转】 g++编译时对'xxxx'未定义的引用问题(undefined reference to)...

    转自:https://blog.csdn.net/killwho/article/details/53785910 引用:http://www.linuxdiyf.com/linux/16754.ht ...

最新文章

  1. 【第四期】如何用Leangoo领歌快速搭建敏捷研发体系分享会
  2. Arduino可穿戴教程认识ArduinoIDE
  3. zabbix 2.2自动安装脚本
  4. RequireJS 主入口加载模块经常会加载失败的问题
  5. Java 9 揭秘(9. 打破模块封装)
  6. jQuery的hide() 、show() 、toggle()
  7. 最新发布!《统计学习方法》第二版无监督学习视频课上线了!
  8. 何时在脚本标记中需要CDATA节?
  9. edge安装包_Chromium版Edge浏览器将支持多平台,Windows版支持IE模式
  10. maven项目在eclipse启动报错:java.lang.ClassNotFoundException
  11. CSUOJ 1170 A sample problem
  12. mysql5.7 主从复制的正常切换【转】
  13. CSharp中委托(一)委托、匿名函数、lambda表达式、多播委托、窗体传值、泛型委托
  14. 最优DP转LVDS解决方案|低成本DP to LVDS转换设计|CS5211方案优势
  15. Oracle PL/SQL 循环
  16. 干货分享!华为模拟器Web配置防火墙
  17. 安卓java的提示错误怎么办_java – Android,如何从try的错误中显示一个对话框?...
  18. The Shawshank Redemption-8
  19. 高等数学第七版 上册 第一章 函数与极限1
  20. ckeditor提交时判断是否为空

热门文章

  1. 【HNOI2019】部分题简要题解
  2. 基于MaxCompute打造轻盈的人人车移动端数据平台
  3. 微信小程序项目,实现图书搜索高阶组件:
  4. Druid 在spring中的配置
  5. CentOS YUM / RPM Error Signature Key ID BAD
  6. 全球域名解析商域名增量Top10:万网增量及涨幅皆第三
  7. MSN Editor 0DAY
  8. 人际交往的“三有三避”
  9. Effective C# 原则34:创建大容量的Web API(译)
  10. 60 分钟极速入门 PyTorch