全部博文(263)
分类: C/C++
2009-10-26 02:47:22
:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://nforcex.blogbus.com/logs/6204594.html
[1]
#error token-string(记号序列)
将使预处理器打印包含该记号序列的诊断信息;Error directives
produce compiler-time error messages.
The error messages include the argument
token-string and are currently not subject to macro expansion. These directives
are most useful for detecting programmer inconsistencies and violation of
constraints during preprocessing. The following example demonstrates error
processing during
preprocessing:
--------------------------------------------------------
#if
!defined(__cplusplus)
#error C++ compiler
required.
#endif
--------------------------------------------------------
When
#error directives are encountered, compilation terminates.
[2]
#pragma
token-string(记号序列)
将使预处理器执行一个与具体实现有关的操作.无法识别的pragma(编译指示)将被忽略掉.
Each
implementation of C and C++ supports some features unique to its host machine or
operating system. Some programs, for instance, need to exercise precise control
over the memory areas where data is placed or to control the way certain
functions receive parameters. The #pragma directives offer a way for each
compiler to offer machine- and operating system-specific features while
retaining overall compatibility with the C and C++ languages. Pragmas are
machine- or operating system-specific by definition, and are usually different
for every compiler.
Pragmas can be used in conditional statements, to provide
new preprocessor functionality, or to provide implementation-defined information
to the compiler. The Microsoft C and C++ compilers recognize the following
pragmas:
alloc_text auto_inline bss_seg
check_stack code_seg
comment component
conform1 const_seg
data_seg
deprecated fenv_access float_control
fp_contract function
hdrstop include_alias
init_seg1
inline_depth inline_recursion
intrinsic
make_public managed
message omp
once optimize
pack pointers_to_members1 pop_macro
push_macro region,endregion runtime_checks
section setlocale unmanaged
vtordisp1 warning
PS:Supported only by the C++
compiler.
The token-string is a series of characters that gives a specific
compiler instruction and arguments, if any. The number sign (#) must be the
first non-white-space character on the line containing the pragma; white-space
characters can separate the number sign and the word pragma. Following #pragma,
write any text that the translator can parse as preprocessing tokens. The
argument to #pragma is subject to macro expansion.
If the compiler finds a
pragma it does not recognize, it issues a warning, but compilation
continues.
Some pragmas provide the same functionality as compiler options.
When a pragma is encountered in source code, it overrides the behavior specified
by the compiler option. For example, if you specified /Zp8, you can override
this compiler setting for specific portions of the code with pack:
cl /Zp8
...
- packing is 8
// ...
#pragma pack(push, 1) - packing is now 1
//
...
#pragma pack(pop) - packing is 8
[3]
#
不执行任何操作
[dictionary]pragma:附注,注记,编译指示
例如:
#pragma once
Specifies that the file will be included (opened) only
once by the compiler when compiling a source code file.
// header.h
#pragma once
This can reduce build times as the compiler
will not open and read the file after the first #include of the module.
#pragma unmanaged
譬如:“C++/CLI”也即是managed programming language for Visual
C++ 2005,如果在代码前面注明#pragma
unmanaged,也就把被托管的本应该生成CIL的C++中间代码改为交给系统底层以传统的方式执行,而不是用CLR运行。