/** 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.

关于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. 不为人知的网络编程(九):理论联系实际,全方位深入理解DNS

    本文原作者:selfboot,博客地址:selfboot.cn,Github地址:github.com/selfboot,感谢原作者的技术分享. 1.引言 对于 DNS(Domain Name Sys ...

  2. 2019年9月Github上最热门的JavaScript开源项目

      2019年9月Github上最热门的JavaScript开源项目 前端开发 前端开发 微信号 qianduan1024 功能介绍 专注于Web前端技术文章分享,包含JavaScript.HTML5 ...

  3. Java泛型类型擦除与运行时类型获取

    Java的泛型大家都知道是类型擦除的方式实现的,“编译器会进行泛型擦除”是一个常识了(实际擦除的是参数和自变量的类型).“类型擦除” 并非像许多开发者认为的那样,在 <..> 符号内的东西 ...

  4. OpenGL光照3:光源

    本文是个人学习记录,学习建议看教程 https://learnopengl-cn.github.io/ 非常感谢原作者JoeyDeVries和多为中文翻译者提供的优质教程 的内容为插入注释,可以先跳过 ...

  5. Python爬取前程无忧网站上python的招聘信息

    前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 我姓刘却留不住你的心 PS:如有需要Python学习资料的小伙伴可以 ...

  6. linux上文件挂载的案例

    cat /etc/fstab 将172.20.20.117上的172.20.20.117:/data/nfs/zichan/目录挂载到172.20.20.112机器上,其实类似目录共享 在需要挂载的机 ...

  7. 高版本 MySQL 导出的脚本到低版本 MySQL 中执行时报错

    导入 MySQL 脚本时报错:[ERR] 1273 - Unknown collation: 'utf8mb4_0900_ai_ci'低版本还不支持 utfmb4 这个字符集 解决方法:将 sql 脚 ...

  8. tomcat配置通过域名访问项目

    tomcat配置通过域名访问项目,是修改conf/server.xml里面的配置信息实现.具体如下: (1)修改Connector节点的port属性值 <Connector port=" ...

  9. netcore之RabbitMQ入门

    简介 RabbitMQ是实现了高级消息队列协议(AMQP)的开源消息中间件,基于Erlang语言编写. AMQP是什么 AMQP 0-9-1(高级消息队列协议)是一种消息传递协议,它允许一致的客户端应 ...

  10. 4.Java基础_Java类型转换

    import javax.swing.plaf.synth.SynthMenuBarUI; /* 类型转换 自动类型转换: 把一个表示数据范围小的数值或者变量赋值给另一个表示数据范围大的变量 强制类型 ...