`
085567
  • 浏览: 217549 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

C/C++ #error #pragma #

阅读更多

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
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运行。

文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/3_program/c++/cppjs/20091027/180314.html

分享到:
评论

相关推荐

    C/C++ 标准库函数 (中文版)

    C/C++标准库函数手册是C/C++程序员必备的参考资料,它详细地介绍了C/C++语言中各种标准库函数的用途、语法和使用方式。标准库中包含了输入输出处理、字符串操作、数学计算、时间日期处理、内存管理等函数,此外C++...

    #pragma使用详解 .pdf

    `#pragma` 是 C 和 C++ 编程语言中的一个预处理指令,用于控制编译器的行为。它允许程序员在不违反语言标准的情况下利用特定编译器的功能。`#pragma` 的语法灵活多变,支持多种参数,这些参数通常用于调整编译过程中...

    #pragma预处理指令用法详解

    在C/C++编程中,预处理指令(Preprocessor Directives)是一种特殊的语句,它们在编译之前由预处理器处理。`#pragma`指令是预处理指令的一种,用于指示编译器执行某些操作或者改变编译器的行为。与`#define`, `#...

    预处理指令#pragma讲解

    在C/C++编程中,预处理指令(Preprocessor Directives)是编译前的一种特殊机制,用于控制编译器的行为。其中,`#pragma` 是一种非常强大的预处理指令,它可以用来设置编译器的状态或者指示编译器完成一些特定的动作...

    c++预处理指令

    这些指令可以在不同的机器和操作系统上编译,以保持C和C++完全兼容。 #pragma是C++语言中最复杂的预处理指令,提供了多种功能,例如指定链接器选项、屏蔽警告、控制数据存放的内存区域等。下面是常用的几个#pragma...

    #pragma 预处理指令详解

    在C和C++编程语言中,预处理指令(Preprocessor Directives)是编译前的一个重要组成部分,用于控制编译器的行为或执行某些特殊的任务。其中,`#pragma`指令作为一种特殊类型的预处理指令,其功能十分强大且灵活多变...

    #pragma预处理命令整理

    `#pragma`是C++中一种特殊的预处理指令,主要用于向编译器发送特定的非标准请求。这些请求可能与特定平台、编译器特性或者优化相关。由于`#pragma`的具体实现依赖于编译器,因此不同的编译器可能会有不同的`#pragma`...

    #pragma的用法

    `#pragma` 指令是 C 和 C++ 编译器中的一种预处理指令,它可以用来设定编译器的状态或者指示编译器完成一些特定的动作。下面是 `#pragma` 指令的一些常用参数和用法: (1) `message` 参数 `message` 参数能够在...

    #pragma 预处理指令详解.pdf

    在深入探讨C和C++编程的世界中,#pragma指令扮演着一个关键角色,尤其在预处理阶段。虽然它不是语言标准的一部分,而是编译器特性的延伸,但它提供了强大的工具,使开发者能够更精细地控制编译过程,无需直接修改...

    vc一些东西pragma

    在C/C++编程中,`#pragma`指令是一种预处理器指令,被广泛应用于Microsoft Visual C++(VC)编译器中,用于控制编译器的行为,如代码布局、警告信息管理、资源管理等。下面我们将详细探讨`#pragma`指令的一些关键...

    Change IP.rar_Change_c/C++

    本文将深入探讨使用C/C++编程语言如何实现这一功能,并结合"Change IP.rar_Change_c/C++"这个压缩包中的资源进行讲解。 首先,我们需要理解IP地址在网络中的作用。IP(Internet Protocol)地址是互联网上设备的唯一...

    #pragma指令用法汇总和解析

    在 C++ 编程中,`#pragma` 是一种预处理器指令,用于向编译器提供非标准的信息或指示。`#pragma` 不是语言的一部分,而是编译器扩展,主要用于控制编译器的行为,例如调整警告级别、指定代码段的位置等。以下是对...

    #pragma指令

    在软件开发领域,尤其是C/C++编程中,`#pragma`指令是一种预处理器指令,被广泛用于向编译器传递特定的信息或控制编译过程中的某些行为。它允许开发者以编译器特定的方式进行优化、调试或配置代码。下面将详细介绍`#...

    Pragma用法.doc

    `Pragma`是C++语言中的一个预处理器指令,它允许程序员对编译器的行为进行一些特殊的控制。在本文中,我们将深入探讨四个主要的Pragma用法:`#pragma once`、`#pragma message`、`#pragma warning`以及`#pragma ...

    c/c++函数库说明(api)html版

    所有的 C / C++ 函数 Constructors (cppstring) Constructors (cppvector) Operators (cppbitset) Operators (cppdeque) Operators (cppstack) Operators (cppstring) Operators (cppvector) abort (stdother...

    pragma使用教程

    pragma 指令是 C 和 C++ 语言中的预处理指令,它的作用是设定编译器的状态或者是指示编译器完成一些特定的动作。pragma 指令对每个编译器给出了一个方法,在保持与 C 和 C++ 语言完全兼容的情况下,给出主机或操作...

Global site tag (gtag.js) - Google Analytics