/** This is a introduction of how to use pragma. */

 #pragma once /// This is used for include the header once.
/**
Note that this is certain for VS compiler but not certain for other compilers that not support this.
As this is not an orginal C++ standard.
Use #ifndef _GUARD_
#define _GUARD_
#endif // _GUARD_ for a portable program. And if your environment is allowed use #pragma once for first option.
Casue #ifndef-#endif will make preprocessor symbol which will ended in symbol collisions and pollute global namespace.
*/ #pragma comment( [type], "name" ) /// This is to tell the compiler to add certain contents in .obj files.
/**
for type
\compiler put the compiler version and name in .obj, which will be ignored by compiler.
i.o
#pragma comment( compiler ) // no "name" input, or error caused. \exestr put the "name" inside .obj won`t be loaded in memory but will be searched by dumpbin.
i.p
#pragma comment( exestr, "versionCode" ) // you can use this to embeded the version code in your exe files. \lib use this to add lib in your projects.
i.o
#pragma comment( lib, "Gdiplus" ) // which add the Gdiplus.lib for compiler. \linker put link file in your project instead of command line and environment settings.
i.o
#pragma comment( linker, "/include:__mySymbol" ) // use /include to force adding in.
There are also other options
/DEFAULTLIB /EXPORT /INCLUDE /MERGE /SECTION see msdn for details \user put the "name" inside .obj, which will be ignored by compiler.
i.o
#pragma comment( user, "Compiled on"__DATE__" at "__TIME__ ) // put the compile date in .obj
*/ #pragma message( "message text" ) /// This will output text when your compiler process to that part.
/**
In which, this is useful for you to know which kind of header file is included
when you are programming in multi-environments.
*/ #pragma code_seg( [ push | pop ], [ identifier ], "segment-name" | "segment-class" ) /// Define the segment in .obj files.
/**
By default, the segment of a function is put in .text segment.
\push add an record in the stack in compiler by record name or segment.
\pop take the top of the stack in compiler by record name or segment.
\identifier while push, this make you push a record name.
i.o
#pragma code_seg( push, r1, "textOne" )
Which push the function under as the record r1 under .text segment named .textOne
. */ #pragma hdrstop /// Indicate that the pre-compile ended here.
/**
So you can use this to make some head files pre-compiled.
Or you may change the priority of some files whne you used #pragma package( smart_init )
*/ #pragma warning( [ warning-specifier : warning-number-list ]; [ warning-specifier : warning-number-list ] ) /// Modify the warning for compiler.
/**
for waring-specifier
\once warn only once
\disable disable warning
\default reset to default level
\error make warning info as error
i.o
#pragma warning( disable: 4507 64; once: 4385; error: 164 )
#pragma warning( pop ) // pop the last warning info in stack and other modify before this command canceled.
. */ #pragma auto_inline( [ on | off ] ) /// Turn on or of the autoinline function for compiler. #pragma inline_depth( [ 0...255 ] ) /// Used for those function marked inline or _inline to decide times of the function calls expand. #pragma inline_recursion( [ 0...255 ] ) /// Used for those function marked inline or _inline to decide times of the recursive function calls expand.
/** Note that this require /Ob option setted to 1 or 2 for compiler. */ #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.
/**
This is useful for 3rd-party dlls whick requiring initialization.
\compiler remain Microsof C run-time order. Constructed first.
\lib marked as compiler and before any others.
\user available to any users but construted last.
*/

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

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

最新文章

  1. svn: E155004 is already locked 解决方案
  2. sql2005下载和安装
  3. Java 泛型 协变式覆盖和泛型重载
  4. Swift4.0 Array详解
  5. 基于docker实现哨兵集群部署
  6. 动车上的书摘-java网络 连接服务器
  7. MySQL的时间字段转换
  8. R语言使用RMySQL连接及读写Mysql数据库
  9. [AWS] User management
  10. random module
  11. pickle 继承
  12. Linux下进程隐藏的方法及其对抗
  13. Word Ladder I & II
  14. [转] 红帽7搭建Zabbix监控
  15. python下操作redis
  16. META http-equiv="refresh" 实现网页自动跳转
  17. 转怎么让VI支持中文显示
  18. MethodTrace 生成的trace文件为空
  19. CSS3 loading效果全
  20. 一个轻量级AOP的实现(开源)

热门文章

  1. 《细说PHP》第四版 样章 第23章 自定义PHP接口规范 10
  2. 实验:用Unity抓取指定url网页中的所有图片并下载保存
  3. PHP JWT token实现
  4. Python Turtle绘画初学编程——六芒星,浪形圈
  5. C#上手练习2(FOR语句)
  6. C# convert between Image and Base64string
  7. python基础(32):进程(二)
  8. 专访腾讯方亮:WeTest品牌全面升级,“好的产品一定深谙人性”
  9. 表单_HTML
  10. Element-ui中自定义表单校验规则