1.#error Directive (C/C++)

The #error directive emits a user-specified error message at compile time and then terminates the compilation.

#error    token-string

The error message that this directive emits includes the token-string parameter. The token-string parameter is not subject to macro expansion. This directive is most useful during preprocessing for notifying the developer of a program inconsistency or the violation of a constraint. The following example demonstrates error processing during preprocessing:

#if    !defined(__cplusplus)
#error C++ compiler required.
#endif

2.#line Directive (C/C++)

The #line directive tells the preprocessor to change the compiler's internally stored line number and filename to a given line number and filename.

#line    digit-sequence ["filename"]

The compiler uses the line number and optional filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is processed.

The digit-sequence value can be any integer constant. Macro replacement can be performed on the preprocessing tokens, but the result must evaluate to the correct syntax. The filename can be any combination of characters and must be enclosed in double quotation marks (" "). Iffilename is omitted, the previous filename remains unchanged.

You can alter the source line number and filename by writing a #line directive. The translator uses the line number and filename to determine the values of the predefined macros __FILE__ and __LINE__. You can use these macros to insert self-descriptive error messages into the program text. For more information on these predefined macros, see Predefined Macros.

The __FILE__ macro expands to a string whose contents are the filename, surrounded by double quotation marks (" ").

If you change the line number and filename, the compiler ignores the previous values and continues processing with the new values. The #linedirective is typically used by program generators to cause error messages to refer to the original source file instead of to the generated program.

The following examples illustrate #line and the __LINE__ and __FILE__ macros.

In this statement, the internally stored line number is set to 151 and the filename is changed to copy.c.

#line    151 "copy.c"

In this example, the macro ASSERT uses the predefined macros __LINE__ and __FILE__ to print an error message about the source file if a given "assertion" is not true.

#define ASSERT(cond)
if( !(cond) )\
{printf( "assertion error line %d, file(%s)\n", \
__LINE__, __FILE__ );}

3.#undef Directive (C/C++)

Removes (undefines) a name previously created with #define.

#undef    identifier

The #undef directive removes the current definition of identifier. Consequently, subsequent occurrences of identifier are ignored by the preprocessor. To remove a macro definition using #undef, give only the macro identifier ; do not give a parameter list.

You can also apply the #undef directive to an identifier that has no previous definition. This ensures that the identifier is undefined. Macro replacement is not performed within #undef statements.

The #undef directive is typically paired with a #define directive to create a region in a source program in which an identifier has a special meaning. For example, a specific function of the source program can use manifest constants to define environment-specific values that do not affect the rest of the program. The #undef directive also works with the #if directive to control conditional compilation of the source program.See The #if, #elif, #else, and #endif Directives for more information.

In the following example, the #undef directive removes definitions of a symbolic constant and a macro. Note that only the identifier of the macro is given.

#define WIDTH 80
#define ADD( X, Y ) ((X) + (Y))
.
.
.
#undef WIDTH
#undef ADD

Microsoft Specific

Macros can be undefined from the command line using the /U option, followed by the macro names to be undefined. The effect of issuing this command is equivalent to a sequence of #undef macro-name statements at the beginning of the file.

END Microsoft Specific

参考:

http://msdn.microsoft.com/zh-cn/library/3sxhs2ty.aspx

assert()函数用法总结

C语言预处理命令的更多相关文章

  1. 不可或缺 Windows Native (4) - C 语言: 预处理命令,输入,输出

    [源码下载] 不可或缺 Windows Native (4) - C 语言: 预处理命令,输入,输出 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 预处理命令 输入 ...

  2. C 语言入门第八章--C语言预处理命令

    例如:#include ,这种以#号开头的命令称为预处理命令. ===C语言宏定义(#define的用法)==== #define 叫做宏定义命令,它也是C语言预处理命令的一种.所谓宏定义,就是用一个 ...

  3. C语言预处理命令总结大全

    C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...

  4. C语言预处理命令详解

    一  前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的工作.预处理指令指示在程序正式编译前就由编译器进行的操作,可放在程序中任何位置. 预处理是C语言的一个重要功能 ...

  5. C08 C语言预处理命令

    目录 宏定义 文件包含 条件编译 预处理命令 C语言的预处理:在编译之前进行的处理,不进行编译. C语言的预处理功能有: 宏定义 文件包含 条件编译 预处理命令以符号“#”开头.. 宏定义 不带参数的 ...

  6. C语言预处理命令总结大全 :宏定义

    C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...

  7. [转]C语言预处理命令详解

    转载:https://www.cnblogs.com/clover-toeic/p/3851102.html 一  前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的 ...

  8. (61)C语言预处理命令详解

    一  前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的工作.预处理指令指示在程序正式编译前就由编译器进行的操作,可放在程序中任何位置. 预处理是C语言的一个重要功能 ...

  9. C/C++编程笔记:C语言预处理命令是什么?不要以为你直接写#就行!

    很多小伙伴在自己写代码的时候,已经多次使用过#include命令.使用库函数之前,应该用#include引入对应的头文件.其实这种以#号开头的命令称为预处理命令. C语言源文件要经过编译.链接才能生成 ...

  10. C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)

    转自:http://www.kuqin.com/language/20090806/66164.html 预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器.可见预处理过程先于编译器 ...

随机推荐

  1. Delphi CxGrid 汇总(4)

    1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...

  2. java基础笔记

    1. 成员变量会自动的进行初始化,但是局部变量不会: 2. equals传引用值,==传地址值:当一个对象是引用类型时,就必须使用equals进行比较. 3. 继承:实现代码的复用,继承关系以一种验证 ...

  3. dump buffer cache

    1.基础内容: ALTER SESSION SET EVENTS 'immediate trace name buffers level n'; n取值意义: 1 只转储buffer header. ...

  4. Ruby判断文件是否存在

    flag = FileTest::exist?("LochNessMonster") flag = FileTest::exists?("UFO") # exi ...

  5. EMVTag系列2《磁条等效数据》

    Ø 57  磁条2等效数据 L: var. up to 19 -M(必备):此数据必须存在并提供给终端,终端在读应用数据过程中,如果没有读到必备数据,终端中止交易 按GB/T 17552,磁条2的数据 ...

  6. DrawerLayout带有侧滑功能的布局类(1)

    DrawerLayout: DrawerLayout顾名思义就是一个管理布局的.使用方式可以与其它的布局类类似. DrawerLayout带有滑动的功能.只要按照drawerLayout的规定布局方式 ...

  7. iOS学习之UI自定义cell

    一.自定义Cell 为什么需要自定义cell:系统提供的cell满足不了复杂的样式,因此:自定义Cell和自定义视图一样,自己创建一种符合我们需求的Cell并使用这个Cell.如下图所示的这些Cell ...

  8. 012--VS2013 C++ 斜角景物地图贴图-位图

    因为bmp图片上传不了,只能截图啦 //全局变量HDC mdc;HBITMAP fullmap;//声明位图对象,在初始化函数中完成的斜角地图会保存在这个位图中const int rows = 10, ...

  9. verilog实现的16位CPU单周期设计

    verilog实现的16位CPU单周期设计 这个工程完成了16位CPU的单周期设计,模块化设计,包含对于关键指令的仿真与设计,有包含必要的分析说明. 单周期CPU结构图 单周期CPU设计真值表与结构图 ...

  10. typings的理解

    简介一些js库扩展了JavaScript的特性和语法,但是TypeScript编译器并不识别,通过typings.json配置可以辅助IDE,给出有智能的提示信息,以及重构的依据.因此需要在typin ...