2011年 03月 03日 星期四 15:47:42 CST
/* "__FILE__"是预定义的宏(也叫内置宏),值是所在文件的文件名(字符串字面量) */
/* "__LINE__"是预定义的宏,值是调用的语句所在文件中的行数(是十进制常量) */
/* assert.h standard header */
#undef assert /* 良性取消assert定义 */
#ifdef NDEBUG
#define assert(test) ((void) 0) /* 如果已定义了NDEBUG,那么assert函数不执行任何操作 */
#else
void _Assert(char *);
#define _STR(x) _VAL(x)
#define _VAL(x) #x /* 井号在此是预处理运算符——字符串化运算符 */
#define assert(test) ((test) ? (void) 0 \ /* "(void) 0"表示什么也不做 */
: _Assert(__FILE__ ":" _STR(__LINE__) " " #test)) /* 使用了条件表达式"a ? b : c" */
/* 理解"_STR(__LINE__)":宏定义里有用'#'或'##'的地方宏参数是不会再展开的 */
#endif
/* xassert.c */ /* 库中隐藏的函数和数据对象通常占据以x开头命名的C源文件 */
/* _Assert function */
#include <assert.h>
#include <stdio.h> /* fputs函数在stdio.h中声明 */
#include <stdlib.h> /* abort函数在stdlib.h中声明 */
void _Assert(char *mesg)
{
fputs(mesg, stderr); /* 把字符串写到标准输出流stderr里 */
fputs(" -- assertion failed\n", stderr);
abort(); /* 调用函数abort异常终止程序的执行 */
}
/* 源码来自 The Standard C Library, by P.J.Plauger */
/* 代码注释为原创 */
分享到:
相关推荐
C语言函数库,包含 C 标准库、IO 函数、字符处理函数、字符串函数、数学函数、时间和日期函数、其它函数等数百个常用的C语言函数,文档中对常用函数库的函数原型、详细功能、使用示例等进行了详细的介绍说明,。...
* <assert.h> : Diagnostics * <ctype.h> : Character Class Tests * <errno.h> : Error Codes Reported by (Some) Library Functions * <float.h> : Implementation-defined Floating-Point Limits * <limits....
6 诊断 <assert.h> . 43 7 变长变元表 <stdarg.h> 44 8 非局部跳转 <setjmp.h> . . . . . . . . . . 45 9 信号处理 <signal.h> . . . . . 46 10 日期与时间函数 <time.h> . . . . 48 11 由实现定义的限制 ...
英文版C语言标准库,Word文档 Contents • <assert.h> : Diagnostics • <ctype.h> : Character Class Tests • <errno.h> : Error Codes Reported by (Some) Library Functions • <float.h> : Implementation-...
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结
#include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include <errno.h> //定义错误码 #include <float.h> //浮点数处理 #include <fstream.h> //文件输入/输出 #include <iomanip.h> //参数化...
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结
B.6 诊断:<assert.h> B.7 变量变元表:<stdarg.h> B.8 非局部跳转:<setjmp.h> B.9 信号处理:<signal.h> B.10 日期与时间函数:<time.h> B.11 由实现定义的限制:<limits.h>和 <float.h> 附录C 变更小结 ...
主要介绍了C标准库<assert>的实现,主要包括了<assert>的基本概念、实现及用法等,需要的朋友可以参考下
C标准库源代码\ASSERT.H C标准库源代码\ATOF.C C标准库源代码\ATONEXIT.C C 标准库源代码\ATOX.C C标准库源代码\AWINT.H C标准库源代码\AW_COM.C C标准库源代码\A_CMP.C C 标准库源代码\A_ENV.C C标准库源代码\A_LOC...
本文实例讲解了C标准库<assert>的实现过程及相关用法。分享给大家供大家参考。具体分析如下: 一、背景知识 头文件<assert>唯一的目的就是提供assert宏定义,可以在程序中关键的地方使用这个宏来进行断言。如果一处...
assert.h ctype.h errno.h math.h float.h limits.h 标准库 等
#include<stdio.h> main() { FILE *fp; char ch; if((fp=fopen("e10_1.c","rt"))==NULL) { printf("Cannot open file strike any key exit!"); getch(); exit(1); } ch=fgetc(fp); while (ch!=EOF) { putchar(ch); ...
阮一峰《C 语言教程》入门 C 语言教程 简介 基本语法 变量 运算符 流程控制 数据类型 ...标准库 assert.h ctype.h errno.h float.h inttypes.h iso646.h limits.h locale.h math.h signal.h stdint.h
我们只需要标准库中可用的库: #include <iostream> #include <fstream> #include <map> #include <array> #include <assert> #include <string> #include <numeric> #include <algorithm> #include <vector> #...
难道在C语言中一个结构不能包含指向自己的指针吗? . . . . 3 1.7 怎样建立和理解非常复杂的声明?例如定义一个包含N 个指向返 回指向字符的指针的函数的指针的数组? . . . . . . . . . . . . . . 3 1.8 函数只定义...