C标准库C99头文件
- <assert.h>
- <complex.h>
- <ctype.h>
- <errno.h>
- <fenv.h>
- <float.h>
- <inttypes.h>
- <iso646.h>
- <limits.h>
- <locale.h>
- <math.h>
- <setjmp.h>
- <signal.h>
- <stdalign.h>
- <stdarg.h>
- <stdatomic.h>
- <stdbit.h>
- <stdbool.h>
- <stdckdint.h>
- <stddef.h>
- <stdint.h>
- <stdio.h>
- <stdlib.h>
- <stdnoreturn.h>
- <string.h>
- <tgmath.h>
- <threads.h>
- <time.h>
- <uchar.h>
- <wchar.h>
- <wctype.h>
本文章是持续更新,对于C99中的头文件进行分析解读和示例。
<assert.h>
Conditionally compiled macro that compares its argument to zero.
通过查看源代码,其中的主要函数如下:
__BEGIN_DECLS
/* This prints an "Assertion failed" message and aborts. */
extern void __assert_fail (const char *__assertion, const char *__file,
unsigned int __line, const char *__function)
__THROW __attribute__ ((__noreturn__));
/* Likewise, but prints the error text for ERRNUM. */
extern void __assert_perror_fail (int __errnum, const char *__file,
unsigned int __line, const char *__function)
__THROW __attribute__ ((__noreturn__));
/* The following is not at all used here but needed for standard
compliance. */
extern void __assert (const char *__assertion, const char *__file, int __line)
__THROW __attribute__ ((__noreturn__));
__END_DECLS
#define assert(expr) \
((void) sizeof ((expr) ? 1 : 0), __extension__ ({
\
if (expr) \
; /* empty */ \
else \
__assert_fail (#expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \
}))
#endif
通常使用断言在程序中对表达式的真假做判断。示例代码如下:
int n = 1;
assert( n > 1);
运行的结果是:
test: src/pmscore.c:8: welcomeMessage: Assertion `n > 1' failed.
<complex.h>
(C99) Complex number arithmetic
这个不用多说,数学上的复数处理和计算,通常情况下使用不到。这里的注释挺有趣,since ISO C99 is out hopefully,直白的说没希望了。
/* We might need to add support for more compilers here. But since ISO
C99 is out hopefully all maintained compilers will soon provide the data
types `float complex' and `double complex'. */
#if __GNUC_PREREQ (2, 7) && !__GNUC_PREREQ (2, 97)
# define _Complex __complex__
#endif
#define complex _Complex
/* Narrowest imaginary unit. This depends on the floating-point
evaluation method.
XXX This probably has to go into a gcc related file. */
#define _Complex_I (__extension__ 1.0iF)
/* Another more descriptive name is `I'.
XXX Once we have the imaginary support switch this to _Imaginary_I. */
#undef I
#define I _Complex_I
#if defined __USE_ISOC11 && __GNUC_PREREQ (4

本文主要介绍了C语言标准库中的多个头文件,如<assert.h>用于表达式真假判断,<complex.h>处理复数计算,<ctype.h>判断字符类型等。还提及部分头文件在C99、C11、C23等标准中的特性,以及编译时可能遇到的问题和解决办法。
最低0.47元/天 解锁文章
644

被折叠的 条评论
为什么被折叠?



