码迷,mamicode.com
首页 > 其他好文 > 详细

关于Pragma

时间:2015-11-07 18:55:39      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

 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

标签:

原文地址:http://www.cnblogs.com/cityfn/p/4945767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!