C语言预处理命令
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
C语言预处理命令的更多相关文章
- 不可或缺 Windows Native (4) - C 语言: 预处理命令,输入,输出
[源码下载] 不可或缺 Windows Native (4) - C 语言: 预处理命令,输入,输出 作者:webabcd 介绍不可或缺 Windows Native 之 C 语言 预处理命令 输入 ...
- C 语言入门第八章--C语言预处理命令
例如:#include ,这种以#号开头的命令称为预处理命令. ===C语言宏定义(#define的用法)==== #define 叫做宏定义命令,它也是C语言预处理命令的一种.所谓宏定义,就是用一个 ...
- C语言预处理命令总结大全
C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...
- C语言预处理命令详解
一 前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的工作.预处理指令指示在程序正式编译前就由编译器进行的操作,可放在程序中任何位置. 预处理是C语言的一个重要功能 ...
- C08 C语言预处理命令
目录 宏定义 文件包含 条件编译 预处理命令 C语言的预处理:在编译之前进行的处理,不进行编译. C语言的预处理功能有: 宏定义 文件包含 条件编译 预处理命令以符号“#”开头.. 宏定义 不带参数的 ...
- C语言预处理命令总结大全 :宏定义
C程序的源代码中可包括各种编译指令,这些指令称为预处理命令.虽然它们实际上不是C语言的一部分,但却扩展了C程序设计的环境.本节将介绍如何应用预处理程序和注释简化程序开发过程,并提高程序的可读性.ANS ...
- [转]C语言预处理命令详解
转载:https://www.cnblogs.com/clover-toeic/p/3851102.html 一 前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的 ...
- (61)C语言预处理命令详解
一 前言 预处理(或称预编译)是指在进行编译的第一遍扫描(词法扫描和语法分析)之前所作的工作.预处理指令指示在程序正式编译前就由编译器进行的操作,可放在程序中任何位置. 预处理是C语言的一个重要功能 ...
- C/C++编程笔记:C语言预处理命令是什么?不要以为你直接写#就行!
很多小伙伴在自己写代码的时候,已经多次使用过#include命令.使用库函数之前,应该用#include引入对应的头文件.其实这种以#号开头的命令称为预处理命令. C语言源文件要经过编译.链接才能生成 ...
- C语言预处理命令之条件编译(#ifdef,#else,#endif,#if等)
转自:http://www.kuqin.com/language/20090806/66164.html 预处理过程扫描源代码,对其进行初步的转换,产生新的源代码提供给编译器.可见预处理过程先于编译器 ...
随机推荐
- 银河英雄传说 (codevs 1540) 题解
[问题描述] 公元五八○一年,地球居民迁移至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰 ...
- 条件放在left join后面和where后面
有这样一个查询的差异: 两张表如下: 语句在这里: create table #AA ( ID int, Name nvarchar() ) insert into #AA ,'项目1' union ...
- Storm入门学习随记
推荐慕课网视频:http://www.imooc.com/video/10055 ====Storm的起源. Storm是开源的.分布式.流式计算系统 什么是分布式呢?就是将一个任务拆解给多个计算机去 ...
- linux 修改系统时间
首先进入/proc/sys/xen,执行以下命令 [root@test]#cd /proc/sys/xen[root@test]#echo 1 > independent_wallclock ...
- C# 将DataTable装换位List<T> 泛型
public List<T> GetList<T>(DataTable dt) where T:new() { List<T> DateLists = new Li ...
- jpg图片在IE6、IE7和IE8下不显示解决办法
坑人的IE浏览器,花了我一个小时才找到原因. 原因:IE内核不能渲染CMYK模式的jpg图片,需要转换为RGB模式. 在photoshop里点击菜单栏—图像—RGB模式就行了 引用:http://lg ...
- hdu 2066 一个人的旅行
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2066 一个人的旅行 Description 虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷 ...
- Effective Objective-C 2.0之Note.04
“类族”(class cluster)是一种很有用的模式(pattern),可以隐藏“抽象基类”(abstract base class)背后的实现细节.Objective-C的系统框架中普遍使用此模 ...
- java与IOS之间的RSA加解密
很简单的一个需求,ipad端给密码RSA加密,传到java后台,解密.RSA加密算法是基于一个密钥对的,分为公钥和私钥,一般情况公钥加密,私钥解密,但也可私钥加密,公钥解密.还可以验签,就是先用私钥对 ...
- MVC4.0 WebApi如何自定义返回数据类型
1.客户端可以通过HTTP Accept消息头来通知服务器客户端想要什么样的MIME类型数据,例如:application/json则代表告诉服务器想要的是Json数据 2.服务器端撇开客户端的请求类 ...