C标准库源码解剖(9)
C标准库源码解剖(9):控制函数assert.h, setjmp.h和signal.h
分类: C 2009-10-19 23:14 533人阅读 评论(0) 收藏 举报
控制函数用于对C语言程序的标准控制流(如if/else、switch、for等)提供扩展,在头文件assert.h、setjmp.h和signal.h中提供,分别提供表达式断言功能、非本地跳转功能、信号处理功能。
1、assert.h: 提供用于断言的assert宏。程序中若没有定义NDEBUG,则asset(exp)对表达式exp进行断言,若断言为假(即为0),则会调用__assert_fail函数打印一条“断言失败”的消息,并终止程序。若定义了NDEBUG宏,则assert通常为空语句。 view plaincopy to clipboardprint? 1. /* ISO C99 Standard: 7.2

诊断 <assert.h> */
2. #ifdef _ASSERT_H
3. # undef _ASSERT_H
4. # undef assert
5. # undef __ASSERT_VOID_CAST
6. # ifdef __USE_GNU
7. # undef assert_perror
8. # endif
9. #endif /* assert.h */
10. #define _ASSERT_H 1
11. #include <features.h>
12. #if defined __cplusplus && __GNUC_PREREQ (2,95)
13. # define __ASSERT_VOID_CAST static_cast<void>
14. #else
15. # define __ASSERT_VOID_CAST (void)
16. #endif
17. /* void assert (int expression);
18. 如果定义了NDEBUG,什么也不做,如果没有定义,且EXPRESSION为0,则打印一个错误消息,然后终止程序
19. */
20. #ifdef NDEBUG
21. # define assert(expr) (__ASSERT_VOID_CAST (0))
22. /* void assert_perror (int errnum);
c标准库<assert.h>:诊断 <assert.h>中只定义了...<ctype.h>中定义的标准函数列 表如下: <ctype.h...Longjmp with value 1 一般地, setjmp 和 longjmp ...
c 语言函数库 第一章(C 标准库) 1. 2. 3. ...10 1. <assert.h>:诊断 <assert.h>中只定义了...Longjmp with value 1 一般地, setjmp 和 longjmp ...
诊断<assert.h>......信号处理<signal.h>......C 标准库函数,但没有列出一些用途有限的函数以及某些可以简单的从其 他函数合成的函数,也没有包含多字节和...
标准语言概述函数库简介 C语言标准库的历史 标准库...在C89标准中: <assert.h> <ctype.h> <errno.h...setjmp.h signal.h 嵌入式家园 www.embedclub.com...
表 9-1 标准库函数 <assert.h> <ctype.h> <...<signal.h> <stdarg.h> <stddef.h> <stdio.h...<setjmp.h>中定义了两个宏: int setjmp(jmp_buf...
c语言函数库-第一章(C标准库)_IT/计算机_专业...10 1. <assert.h>:诊断 : <assert.h>中只定义...Longjmp with value 1 一般地, setjmp 和 longjmp ...
C标准库函数集(头文件索引)_IT/计算机_专业资料...诊断<assert.h>......8.1 setjmp #include <setjmp.h> int setjmp(jmp_buf env); setjmp()宏把...
<assert.h>:诊断 <assert.h>中只定义了一个带参...<setjmp.h>中定义了两个宏: int setjmp(jmp_buf...在<signal.h>中只定义了两个函数: int signal(...
热门文档