1. /** This is a introduction of how to use pragma. */
  2.  
  3. #pragma once /// This is used for include the header once.
  4. /**
  5. Note that this is certain for VS compiler but not certain for other compilers that not support this.
  6. As this is not an orginal C++ standard.
  7. Use
  8.  
  9. #ifndef _GUARD_
  10. #define _GUARD_
  11. #endif // _GUARD_
  12.  
  13. for a portable program. And if your environment is allowed use #pragma once for first option.
  14. Casue #ifndef-#endif will make preprocessor symbol which will ended in symbol collisions and pollute global namespace.
  15. */
  16.  
  17. #pragma comment( [type], "name" ) /// This is to tell the compiler to add certain contents in .obj files.
  18. /**
  19. for type
  20. \compiler put the compiler version and name in .obj, which will be ignored by compiler.
  21. i.o
  22. #pragma comment( compiler ) // no "name" input, or error caused.
  23.  
  24. \exestr put the "name" inside .obj won`t be loaded in memory but will be searched by dumpbin.
  25. i.p
  26. #pragma comment( exestr, "versionCode" ) // you can use this to embeded the version code in your exe files.
  27.  
  28. \lib use this to add lib in your projects.
  29. i.o
  30. #pragma comment( lib, "Gdiplus" ) // which add the Gdiplus.lib for compiler.
  31.  
  32. \linker put link file in your project instead of command line and environment settings.
  33. i.o
  34. #pragma comment( linker, "/include:__mySymbol" ) // use /include to force adding in.
  35. There are also other options
  36. /DEFAULTLIB /EXPORT /INCLUDE /MERGE /SECTION see msdn for details
  37.  
  38. \user put the "name" inside .obj, which will be ignored by compiler.
  39. i.o
  40. #pragma comment( user, "Compiled on"__DATE__" at "__TIME__ ) // put the compile date in .obj
  41. */
  42.  
  43. #pragma message( "message text" ) /// This will output text when your compiler process to that part.
  44. /**
  45. In which, this is useful for you to know which kind of header file is included
  46. when you are programming in multi-environments.
  47. */
  48.  
  49. #pragma code_seg( [ push | pop ], [ identifier ], "segment-name" | "segment-class" ) /// Define the segment in .obj files.
  50. /**
  51. By default, the segment of a function is put in .text segment.
  52. \push add an record in the stack in compiler by record name or segment.
  53. \pop take the top of the stack in compiler by record name or segment.
  54. \identifier while push, this make you push a record name.
  55. i.o
  56. #pragma code_seg( push, r1, "textOne" )
  57. Which push the function under as the record r1 under .text segment named .textOne
  58. . */
  59.  
  60. #pragma hdrstop /// Indicate that the pre-compile ended here.
  61. /**
  62. So you can use this to make some head files pre-compiled.
  63. Or you may change the priority of some files whne you used #pragma package( smart_init )
  64. */
  65.  
  66. #pragma warning( [ warning-specifier : warning-number-list ]; [ warning-specifier : warning-number-list ] ) /// Modify the warning for compiler.
  67. /**
  68. for waring-specifier
  69. \once warn only once
  70. \disable disable warning
  71. \default reset to default level
  72. \error make warning info as error
  73. i.o
  74. #pragma warning( disable: 4507 64; once: 4385; error: 164 )
  75. #pragma warning( pop ) // pop the last warning info in stack and other modify before this command canceled.
  76. . */
  77.  
  78. #pragma auto_inline( [ on | off ] ) /// Turn on or of the autoinline function for compiler.
  79.  
  80. #pragma inline_depth( [ 0...255 ] ) /// Used for those function marked inline or _inline to decide times of the function calls expand.
  81.  
  82. #pragma inline_recursion( [ 0...255 ] ) /// Used for those function marked inline or _inline to decide times of the recursive function calls expand.
  83. /** Note that this require /Ob option setted to 1 or 2 for compiler. */
  84.  
  85. #pragma init_seg( [ compiler | lib | user ], "section-name" | "func-name" ) /// Specifies a keyword or code section that affects the order in which startup code is executed.
  86. /**
  87. This is useful for 3rd-party dlls whick requiring initialization.
  88. \compiler remain Microsof C run-time order. Constructed first.
  89. \lib marked as compiler and before any others.
  90. \user available to any users but construted last.
  91. */

以上是从网上搜集的关于 #pragma 的一些用法和注意事项,还参考了部分的 msdn.

个人觉得最常用的还是 #pragma once 和 #pragma comment 不过真的碰到多环境的情况用一用 #pragma message 也不错XD.

关于Pragma的更多相关文章

  1. #pragma once与#ifndef #define ...#endif的区别

    1. #pragma once用来防止某个头文件被多次include: #ifndef,#define,#endif用来防止某个宏被多次定义.   2. #pragma once是编译相关,就是说这个 ...

  2. 预处理指令#pragma

    #pragma介绍 #pragma是一个预处理指令,pragma的中文意思是『编译指示』.它不是Objective-C中独有的东西(貌似在C/C++中使用比较多),最开始的设计初衷是为了保证代码在不同 ...

  3. 关于 Pragma 的使用总结

    注意:此文乃是本人阅读多个博客文章后,记下的个人认为重点的地方. 参考文章: 参考1   参考2 #Pragma mark - 用于分离类中的不同功能的方法.(例如,一个 viewController ...

  4. IAR #pragma vector 中断入口地址

    在IAR编译器里用关键字来__interrupt来定义一个中断函数.用#pragma vector来提供中断函数的入口地址. #pragma vector = 0x12    //定时器0溢出中断入口 ...

  5. #pragma pack(push,1)与#pragma pack(1)的区别

    这是给编译器用的参数设置,有关结构体字节对齐方式设置, #pragma pack是指定数据在内存中的对齐方式. #pragma pack (n)             作用:C编译器将按照n个字节对 ...

  6. 你可能不知道的iOS冷知识——#pragma

    Mattt Thompson撰写. Zihan Xu翻译. 发布于2012年10月1日 #pragma 声明是彰显 Objective-C 工艺的标志之一.虽然 #pragma 最初的目的是为了使得源 ...

  7. pragma

    在所有的预处理指令中,#pragma指令可能是最复杂的了,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作.#pragma指令对每个 编译器给出了一个方法,在保持与C和C++语言完全兼容的 ...

  8. 关于#pragma once和#ifndefine组合的区别

    最近在看duilib代码,发现头文件既有#pragma once 又有 #ifndefine...#define,忽然就觉得有点不解,因为据我所知这两者都是防止头文件二次包含的. 经过下面两位的解释后 ...

  9. Pragma如何分组

    Pragma Pragma Mark #pragma mark - 是一个在类内部组织代码并且帮助你分组方法实现的好办法. 我们建议使用 #pragma mark - 来分离: 不同功能组的方法 pr ...

  10. 【C语言】pragma

    ① #pragma comment (lib, "libgsl.a") 这是告诉编译器在编译形成的.obj文件和.exe文件中加一条信息,使得 链接器在链接库的时候要去找libgs ...

随机推荐

  1. XML与DTD(够用)

    1: 概述 1.1 什么是XML 1.2 三个重点 1.3规则 1.4 常用转义 2: Xml声明 XML 中,空格会被保留 XML 以 LF 存储换行 3:Xml标签 4:Xml元素 5:XML 属 ...

  2. 编译安装最新版nettle和gnutls

    编译安装最新版gnutls的时候,总是会出libnettle 3.4.1 was not found的报错信息. 即使编译安装了nettle的最新版3.5之后,依然会报该错. 原因是gnutls编译的 ...

  3. Pycharm 疑难杂症

    1. Pycharm报错:AttributeError: 'NoneType' object has no attribute 'get'的解决办法 https://blog.csdn.net/fre ...

  4. C# WebClient,HttpClient,WebRequest

    static void WebClientDemo() { string url = "https://www.cnblogs.com/Fred1987/p/11843418.html&qu ...

  5. webpack基本使用

    webpack安装时的坑 高版本的webpack除了全局安装webpack外,还需安装webpack-cli,在本地使用时也一样需要这样,不然会出错 webpack使用是的坑 在原始启动webpack ...

  6. Python中最常用的字符串方法!

    字符串是字符序列.Python中内置的string类代表基于Unicode国际字符集的字符串.除了Python中常见的操作外,字符串还有一些专属于它们的附加方法.下图显示了所有这些可用的方法: Pyt ...

  7. 使用原生Ajax进行用户名重复的检验

    title: 使用原生Ajax进行用户名重复的检验(一) date: 2019-01-21 17:35:15 tags: [JavaScript,Ajax] --- Ajax的复习 距离刚开始学aja ...

  8. 基于file上传文件的并发上传(多个文件一起上传到后台并把数据存储的同一条数据中,如 数据库字段videopath,imge。前台发送来的文件file1,file2。 videopath=file1,imge=file2)

    前台代码: <div class="tab-content"> <dl> <dt>所属栏目</dt> <dd> < ...

  9. 版本管理·玩转git(推到远程仓库)

    经过前面的练习,你在本地的仓库里管理代码已经比较熟练了,但如果是团队开发呢,如何配合起来呢? 我们可以把版本仓库放在互联网上,开发者把自己最新的版本推到线上仓库,同时,把线上仓库的最新代码拉到自己本地 ...

  10. Mysql—配置文件my.ini或my.cnf的详解

    [mysqld] log_bin = mysql-bin binlog_format = mixed expire_logs_days = # 超过7天的binlog删除 slow_query_log ...