认识C标准函数库全集-2-测试及定义类文件-assert/errno/ctype/float/limits/locale/stddef
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
参考:https://zh.wikipedia.org/wiki/C标准函数库
https://web.archive.org/web/20050302041944/http://www.infosys.utas.edu.au/info/documentation/C/CStdLib.html
https://www.tutorialspoint.com/c_standard_library/locale_h.htm
继续解析ANSI C标准库中的文件:按照下面个人理解的分类介绍
a. 测试及定义类:用于测试协助的一个文件定义assert.h;用于内部函数错误码的一个文件errno.h;测试字符类别的一个库文件ctype.h;数字限制的两个库文件float.h, limits.h;本地货币数字特性的定义文件locale.h;常用定义文件stddef.h;共计7个文件。
b. 信号处理:处理信号中断定义和处理的一个文件signal.h。
c. 输入输出:输入输出一个处理文件stdio.h。
d. 语言特性: 处理远程跳转一个处理文件setjmp.h,可变参数一个处理文件stdarg.h,共计2个文件。
e. 通用函数:数学处理一个库文件math.h,字符串处理一个库文件string.h,日期时间处理一个库文件time.h,其它工具函数一个库文件stdlib,共计4个文件
测试及定义类的7个文件
注:示例代码来源于turboc
1. assert.h
依赖项stdio.h与stdlib.h,提供assert函数,预定义宏控制项NDEBUG
#include <stdio.h> /* fprintf() prototype & 'stderr' definition */
#include <stdlib.h> /* abort() prototype */#if !defined(NDEBUG)
#define assert(p) if(!(p)){fprintf(stderr,\"Assertion failed: %s, file %s, line %d\n",\#p, __FILE__, __LINE__);abort();}
#else
#define assert(p)
#endif
2. errno.h
依赖项无,声明了外部变量errno与_doserrno,并定义了一系列错误码取值宏声明。
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif/* Dos Error Codes */
#define EZERO 0 /* Error 0 */
#define EINVFNC 1 /* Invalid function number */
#define ENOFILE 2 /* File not found */
...
#define ENOENT 2 /* No such file or directory */
#define EMFILE 4 /* Too many open files */
...
#define EFAULT -1 /* Unknown error */
#define EPERM -1 /* UNIX - not MSDOS */
#define ESRCH -1 /* UNIX - not MSDOS */
...
#define _sys_nerr 35 /* highest defined system error number */
extern int _Cdecl errno;
extern int _Cdecl _doserrno;
3. ctype.h
依赖项无,声明了一个外部变量字符数组_ctype,一系列的字符测试函数–如tolower, toupper, isdigit等。
#define _IS_SP 1 /* is space */
#define _IS_DIG 2 /* is digit indicator */
#define _IS_UPP 4 /* is upper case */
#define _IS_LOW 8 /* is lower case */
#define _IS_HEX 16 /* [A-F or [a-f] */
#define _IS_CTL 32 /* Control */
#define _IS_PUN 64 /* punctuation */extern char _Cdecl _ctype[]; /* Character type array */#define isalnum(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_UPP | _IS_LOW))
#define isalpha(c) (_ctype[(c) + 1] & (_IS_UPP | _IS_LOW))
#define isascii(c) ((unsigned)(c) < 128)
#define iscntrl(c) (_ctype[(c) + 1] & _IS_CTL)
#define isdigit(c) (_ctype[(c) + 1] & _IS_DIG)
#define isgraph(c) ((c) >= 0x21 && (c) <= 0x7e)
#define islower(c) (_ctype[(c) + 1] & _IS_LOW)
#define isprint(c) ((c) >= 0x20 && (c) <= 0x7e)
#define ispunct(c) (_ctype[(c) + 1] & _IS_PUN)
#define isspace(c) (_ctype[(c) + 1] & _IS_SP)
#define isupper(c) (_ctype[(c) + 1] & _IS_UPP)
#define isxdigit(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_HEX))#define _toupper(c) ((c) + 'A' - 'a')
#define _tolower(c) ((c) + 'a' - 'A')
#define toascii(c) ((c) & 0x7f)int _Cdecl tolower(int ch);
int _Cdecl toupper(int ch);
4. limits.h
依赖项无,定义了一系列的char/short/int/long取值范围
#define CHAR_BIT 8#if (((int)((char)0x80)) < 0)
#define CHAR_MAX 0x7F
#define CHAR_MIN 0x80
#else
#define CHAR_MAX 0xFFU
#define CHAR_MIN 0x00
#endif#define SCHAR_MAX 0x7F
#define SCHAR_MIN -128
#define UCHAR_MAX 0xFFU#define SHRT_MAX 0x7FFF
#define SHRT_MIN ((int)0x8000)
#define USHRT_MAX 0xFFFFU#define INT_MAX 0x7FFF
#define INT_MIN ((int)0x8000)
#define UINT_MAX 0xFFFFU#define LONG_MAX 0x7FFFFFFFL
#define LONG_MIN ((long)0x80000000L)
#define ULONG_MAX 0xFFFFFFFFUL
5. float.h
a. 依赖项无。
b. 定义了几个浮点数的外部变量_huge_flt/huge_dble/huge_ldble/_tiny_ldble, 以及一些浮点状态位控制函数_clear87/_control87/_fpreset/_status87。
c. 定义了浮点数的宏定义,有取整方式、精度、浮点指数位、最大值、异常值等。
#define FLT_RADIX 2
#define FLT_ROUNDS 1
#define FLT_GUARD 1
#define FLT_NORMALIZE 1
...
#define DBL_EPSILON 2.2204460492503131E-16
#define FLT_EPSILON 1.19209290E-07F
#define LDBL_EPSILON 1.084202172485504E-19
...
/* smallest positive IEEE normal numbers */
#define DBL_MIN 2.2250738585072014E-308
#define FLT_MIN 1.17549435E-38F
#define LDBL_MIN _tiny_ldble
...#define DBL_MAX_EXP +1024
#define FLT_MAX_EXP +128
#define LDBL_MAX_EXP +16384
...
extern float _Cdecl _huge_flt;
extern double _Cdecl _huge_dble;
extern long double _Cdecl _huge_ldble;
extern long double _Cdecl _tiny_ldble;unsigned int _Cdecl _clear87(void);
unsigned int _Cdecl _control87(unsigned int new, unsigned int mask);
void _Cdecl _fpreset(void);
unsigned int _Cdecl _status87(void);/* 8087/80287 Status Word format */
#define SW_INVALID 0x0001 /* Invalid operation */
#define SW_DENORMAL 0x0002 /* Denormalized operand */
#define SW_ZERODIVIDE 0x0004 /* Zero divide */
#define SW_OVERFLOW 0x0008 /* Overflow */
#define SW_UNDERFLOW 0x0010 /* Underflow */
#define SW_INEXACT 0x0020 /* Precision (Inexact result) */
...
6. locale.h
(turboc中没有找到这个文件,从xcode的库中拿了一些代码做参考。)
- 提供了结构lconv
- 提供了函数setlocale来设置本地化参数,localeconv获取本地设置
- 提供相关使用时用到的宏定义collate/char type/monetary/numeric/time/message。
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
#define LC_MONETARY 3
#define LC_NUMERIC 4
#define LC_TIME 5
#define LC_MESSAGES 6#define _LC_LAST 7 /* marks end */struct lconv {char *decimal_point;char *thousands_sep;char *grouping;char *int_curr_symbol;char *currency_symbol;char *mon_decimal_point;char *mon_thousands_sep;char *mon_grouping;char *positive_sign;char *negative_sign;char int_frac_digits;char frac_digits;char p_cs_precedes;char p_sep_by_space;char n_cs_precedes;char n_sep_by_space;char p_sign_posn;char n_sign_posn;char int_p_cs_precedes;char int_n_cs_precedes;char int_p_sep_by_space;char int_n_sep_by_space;char int_p_sign_posn;char int_n_sign_posn;
};__BEGIN_DECLS
char *setlocale(int, const char *);
struct lconv *localeconv(void);
__END_DECLS
7. stddef.h
无依赖文件,同样声明了外部变量errno,并声明常量size_t, ptrdiff_t, NULL宏定义。
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
typedef long ptrdiff_t;
#else
typedef int ptrdiff_t;
#endif
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif#ifndef NULL
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
#define NULL 0
#else
#define NULL 0L
#endif
#endifextern int _Cdecl errno;
(Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu)
认识C标准函数库全集-2-测试及定义类文件-assert/errno/ctype/float/limits/locale/stddef相关推荐
- ANSI C标准函数库
ANSI C标准函数库 http://blog.chinaunix.net/u2/62910/showart_1161012.html absread()读磁盘绝对扇区函数 原形:int absrea ...
- C标准函数库中获取时间与日期、对时间与日期数据操作及格式化
表示时间的三种数据类型[编辑] 日历时间(calendar time),是从一个标准时间点(epoch)到现在的时间经过的秒数,不包括插入闰秒对时间的调整.开始计时的标准时间点,各种编译器一般使用19 ...
- 软题库 - 软考题库,云题库,智能测试
软题库 - 软考题库,云题库,智能测试 软题库 - 软考题库,云题库,智能测试 posted on 2017-04-17 16:43 lexus 阅读(...) 评论(...) 编辑 收藏 转载于:h ...
- libVLC库下载及测试
[2023-2-26] 1. libVLC下载及测试 [2023-2-26] 1. libVLC库下载及测试 [2023-2-28] 2. Qt 实现libVLC视频显示 文章目录 [2023-2-2 ...
- python扇贝单词书,成功使用Python爬虫扇贝单词库实现自动测试我们的单词量
import time import requests import re from openpyxl import workbook#导入我们要用到的库 from bs4 import Beauti ...
- 【花雕体验】08 行空板硬件控制pinpong库的系列测试(之一)
行空板板身集成了光线传感器.麦克风.蜂鸣器.Wifi.蓝牙.加速度传感器.按键,正面配置有一块LCD彩屏,可实时呈现多种Python运行结果,包括文字.图片.视频,游戏画面,以及数据图表等. [花雕体 ...
- 【花雕体验】10 行空板硬件控制pinpong库的系列测试(之三)
6.基础GPIO使用 行空板引脚操作与pinpong通用语法相同. [花雕体验]01上手行空板 https://blog.csdn.net/weixin_41659040/article/detail ...
- 【花雕体验】09 行空板硬件控制pinpong库的系列测试(之二)
行空板板身集成了光线传感器.麦克风.蜂鸣器.Wifi.蓝牙.加速度传感器.按键,正面配置有一块LCD彩屏,可实时呈现多种Python运行结果,包括文字.图片.视频,游戏画面,以及数据图表等. [花雕体 ...
- c语言程序库文件,c语言标准函数库
本词条缺少概述图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧! 在C语言程序设计里,C 标准函数(C Standard library)是所有符合标准的头文件(head file)的集合,以 ...
最新文章
- 七个算法小仙女,写出一本1200页的深度学习技术手册!(限时公开下载)
- Kali Linux软件更新日报20190623
- 2015第29周五AOP
- CCNA-第七篇-思科私有路由协议-EIGRP-初级
- linux 内核入口地址,linux内核的加载地址和入口地址
- MySQL-事务的实现-redo
- 半导体物理与器件pdf施敏_SiC半导体材料的基本性质和应用
- 2006 年100 款最佳安全工具谱
- linux map内存在哪里分配,linux内存分配与回收
- matlab微带带通滤波器,小型化宽阻带微带带通滤波器的设计方案
- [转]中国著名黑客你知道多少?
- SAP: Query创建教程
- 对话机器人技术简介:问答系统、对话系统与聊天机器人
- linux新硬盘装系统,目前是windows,要全新硬盘安装linux,该怎么操作?
- Exception evaluating SpringEL expression:
- 推荐一个数据库文档生成神器
- Pytorch基础操作 —— 8. 张量转置操作
- QT QTableWidget的用法
- 2022-07-11 Python TCP服务器与客户端
- Java学习路线!2020-2021华为Java面试真题
热门文章
- Qorvo 扩展 750V SiC FET 范围
- 使用建造者模式(Builder Pattern) 设计Excel导出场景,附源码
- RabbitMQ的简单使用
- 近期 0day exploit 满天飞,原来是神秘的以色列公司 Candiru 在捣鬼
- 视频直播质量的评测和实现分享
- 成功解决pydotplus.graphviz.InvocationException: GraphViz‘s executables not found
- Excel如何在excel中根据关键词从字符串中查找并提取
- 共轭梯度法详细推导分析
- CVPR 2019 论文大盘点-超分辨率篇
- ios和安卓手机游戏开发!34岁安卓开发大叔感慨,实战解析