ISO/IEC 9899:1999 编程语言 C 标准指定以 C 语言编写的程序的形式并加以解释。但是,此标准留下许多实现定义的问题,即因编译器而异的问题。本章将详细介绍这些方面的内容。它们很容易与 ISO/IEC 9899:1990 标准本身比较:
每一项均使用 ISO 标准中的相同节文本。
每一项的前面均有 ISO 标准中相应的节号。
圆括号中的编号与 ISO/IEC 9899:1990 标准中的节号对应。
错误消息具有以下格式:
filename, line line number: message
警告消息具有以下格式:
filename, line line number: warning message
其中:
filename 是错误或警告所在文件的名称
line number 是错误或警告所在行的编号
message 是诊断消息
int main (int argc, char *argv[]) { .... } |
argc 是调用程序时所用的命令行参数的数量。在任何 shell 扩展之后,argc 总是至少等于 1,即程序名称。
argv 是指向命令行参数的指针数组。
交互式设备是系统库调用 isatty() 返回非零值的设备。
前 1,023 个字符是有效字符。标识符区分大小写。
前 1,023 个字符是有效字符。标识符区分大小写。
这两个字符集都与 ASCII 字符集相同,并有特定于语言环境的扩展。
无移位状态。
对于 ASCII 部分,一个字符中有 8 位;对于特定于语言环境的扩展部分,一个字符中的位数是 8 的倍数,具体取决于语言环境。
源代码字符与执行字符之间映射相同。
它是最右边字符的数值。例如,'\q' 等于 'q'。如果这样的换码序列出现,则会发出警告。
一个多字符常量,它不是具有从每个字符的数值派生的值的转义序列。
LC_ALL、LC_CTYPE 或 LANG 环境变量指定的有效语言环境。
char 被视为 signed char (SPARC) (x86)。
整数 |
位 |
最小值 |
最大值 |
---|---|---|---|
char (SPARC) (x86) |
8 |
-128 |
127 |
signed char |
8 |
-128 |
127 |
unsigned char |
8 |
0 |
255 |
short |
16 |
-32768 |
32767 |
signed short |
16 |
-32768 |
32767 |
unsigned short |
16 |
0 |
65535 |
int |
32 |
-2147483648 |
2147483647 |
signed int |
32 |
-2147483648 |
2147483647 |
unsigned int |
32 |
0 |
4294967295 |
long (SPARC) v8 |
32 |
-2147483648 |
2147483647 |
long (SPARC) v9 |
64 |
-9223372036854775808 |
9223372036854775807 |
signed long (SPARC) v8 |
32 |
-2147483648 |
2147483647 |
signed long (SPARC) v9 |
64 |
-9223372036854775808 |
9223372036854775807 |
unsigned long (SPARC) v8 |
32 |
0 |
4294967295 |
unsigned long (SPARC) v9 |
64 |
0 |
18446744073709551615 |
long long |
64 |
-9223372036854775808 |
9223372036854775807 |
64 |
-9223372036854775808 |
9223372036854775807 |
|
unsigned long long |
64 |
0 |
18446744073709551615 |
整数转换为较短的 signed 整数时,低阶位从较长的整数复制到较短的 signed 整数中。结果可能为负数。
无符号整数转换为同等长度的 signed 整数时,低阶位从 unsigned 整数复制到 signed 整数。结果可能为负数。
对 signed 类型应用按位操作的结果是操作数的按位操作,包括 sign 位。因此,当且仅当两个操作数中每个对应的位均已置位时,结果中的每个位才置位。
结果的符号与被除数相同,因此,-23/4 的余数是 -3。
float |
|
位 |
32 |
最小值 |
1.17549435E-38 |
最大值 |
3.40282347E+38 |
Epsilon |
1.19209290E-07 |
表 E–3 double 值
double |
|
位 |
64 |
最小值 |
2.2250738585072014E-308 |
最大值 |
1.7976931348623157E+308 |
Epsilon |
2.2204460492503131E-16 |
表 E–4 long double 值
long double |
|
位 |
128 (SPARC) 80 (x86) |
最小值 |
3.362103143112093506262677817321752603E-4932 (SPARC) 3.3621031431120935062627E-4932 (x86) |
最大值 |
1.189731495357231765085759326628007016E+4932 (SPARC) 1.1897314953572317650213E4932 (x86) |
Epsilon |
1.925929944387235853055977942584927319E-34 (SPARC) 1.0842021724855044340075E-19 (x86) |
数舍入为可以表示的最近的值。
数舍入为可以表示的最近的值。
stddef.h 中定义的 unsigned int。
对于 -Xarch=v9,为 unsigned long。
对于指针以及类型为 int、long、unsigned int 和 unsigned long 的值,位模式不变。
stddef.h 中定义的 int。
对于 -Xarch=v9 为 long。
有效寄存器声明数取决于每个函数内使用和定义的模式,并受可供分配的寄存器数的限制。不要求编译器和优化器接受寄存器声明。
访问存储在联合成员中的位模式,并根据访问成员时所用的成员类型解释值。
类型 |
对齐边界 |
字节对齐 |
---|---|---|
char |
字节 |
1 |
short |
半字 |
2 |
int |
字 |
4 |
long (SPARC) v8 |
字 |
4 |
long (SPARC) v9 |
双字 |
8 |
float (SPARC) |
字 |
4 |
double (SPARC) |
双字 (SPARC) 字 (x86) |
8 (SPARC) 4 (x86) |
long double (SPARC) v8 |
双字 (SPARC) 字 (x86) |
8 (SPARC) 4 (x86) |
long double (SPARC) v9 |
四倍长字 |
16 |
pointer (SPARC) v8 |
字 |
4 |
pointer (SPARC) v9 |
四倍长字 |
8 |
long long |
双字 (SPARC) 字 (x86) |
8 (SPARC) 4 (x86) |
内部填充结构成员,以便各个元素在适当的边界上对齐。
结构的对齐与其更严格对齐的成员相同。例如,只包含 char 数据的 struct 无对齐限制,而包含 double 数据的 struct 将按 8 字节边界对齐。
视为 unsigned int。
在存储单元中从高阶到低阶分配位字段。
位字段不可以跨存储单元边界。
这是 int。
对象名称的每个引用构成对该对象的访问。
编译器不施加任何限制。
编译器不施加任何限制。
预处理指令中的字符常量与其在任何其他表达式中的数值相同。
此上下文中的字符常量可以有负值 (SPARC) (x86)。
对于由 < > 限定其名称的文件,先在 -I 选项指定的目录中查找,然后在标准目录中查找。标准目录为 /usr/include,除非使用 -YI 选项指定另一个缺省位置。
对于由引号限定其名称的文件,先在包含 #include 的源文件的目录中查找,然后在 -I 选项指定的目录中查找,最后在标准目录中查找。
如果 < > 或双引号中的文件名以 / 字符开头,则文件名解释为根目录开头的路径名。查找该文件时只能从根目录开始。
支持 include 指令中的带引号文件名。
源文件字符映射至其相应的 ASCII 值。
支持以下 pragma。有关更多信息,请参见2.9 Pragma。
align integer (variable[, variable])
does_not_read_global_data (funcname [, funcname])
does_not_return (funcname[, funcname])
does_not_write_global_data (funcname[, funcname])
error_messages (on|off|default, tag1[ tag2... tagn])
fini (f1[, f2..., fn])
ident string
init (f1[, f2..., fn])
inline (funcname[, funcname])
int_to_unsigned (funcname)
MP serial_loop
MP serial_loop_nested
MP taskloop
no_inline (funcname[, funcname])
nomemorydepend
no_side_effect (funcname[, funcname])
opt_level (funcname[, funcname])
pack(n)
pipeloop(n)
rarely_called (funcname[, funcname])
redefine_extname old_extname new_extname
returns_new_memory (funcname[, funcname])
unknown_control_flow (name[, name])
unroll (unroll_factor)
weak (symbol1 [= symbol2])
环境中总是提供这些宏。
NULL 等于 0。
诊断为:
Assertion failed: statement . file filename, line number
其中:
statement 是使断言失败的语句
filename 是失败所在文件的名称
line number 是失败所在行的编号
isalnum |
ASCII 字符 A-Z、a-z 和 0-9 |
isalpha |
ASCII 字符 A-Z 和 a-z,以及特定于语言环境的单字节字母 |
iscntrl |
值为 0-31 和 127 的 ASCII 字符 |
islower |
ASCII 字符 a-z |
isprint |
特定于语言环境的单字节可输出字符 |
isupper |
ASCII 字符 A-Z |
错误 |
数学函数 |
编译器模式 |
|
---|---|---|---|
|
|
-Xs、-Xt |
-Xa、-Xc |
DOMAIN |
acos(|x|>1) |
0.0 |
0.0 |
DOMAIN |
asin(|x|>1) |
0.0 |
0.0 |
DOMAIN |
atan2(+-0,+-0) |
0.0 |
0.0 |
DOMAIN |
y0(0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
y0(x<0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
y1(0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
y1(x<0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
yn(n,0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
yn(n,x<0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
log(x<0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
log10(x<0) |
-HUGE |
-HUGE_VAL |
DOMAIN |
pow(0,0) |
0.0 |
1.0 |
DOMAIN |
pow(0,neg) |
0.0 |
-HUGE_VAL |
DOMAIN |
pow(neg,non-integal) |
0.0 |
NaN |
DOMAIN |
sqrt(x<0) |
0.0 |
NaN |
DOMAIN |
fmod(x,0) |
x |
NaN |
DOMAIN |
remainder(x,0) |
NaN |
NaN |
DOMAIN |
acosh(x<1) |
NaN |
NaN |
DOMAIN |
atanh(|x|>1) |
NaN |
NaN |
检测到下溢时,除 scalbn 之外的数学函数将 errno 设置为 ERANGE。
在此情况下,它返回第一个参数并发生域错误。
下表列出了 signal 函数可识别的每个信号的语义:
表 E–8 signal 信号的语义
信号 |
不可以。 |
缺省 |
事件 |
---|---|---|---|
SIGHUP |
1 |
退出 |
挂起 |
SIGINT |
2 |
退出 |
interrupt |
SIGQUIT |
3 |
信息转储 |
quit |
SIGILL |
4 |
信息转储 |
非法指令(找到时不重置) |
SIGTRAP |
5 |
信息转储 |
跟踪陷阱(捕获时不重置) |
SIGIOT |
6 |
信息转储 |
IOT 指令 |
SIGABRT |
6 |
信息转储 |
由中止使用 |
SIGEMT |
7 |
信息转储 |
EMT 指令 |
SIGFPE |
8 |
信息转储 |
浮点异常 |
SIGKILL |
9 |
退出 |
中止(找不到,也无法忽略) |
SIGBUS |
10 |
信息转储 |
总线错误 |
SIGSEGV |
11 |
信息转储 |
段违规 |
SIGSYS |
12 |
信息转储 |
系统调用参数错误 |
SIGPIPE |
13 |
退出 |
写在管道上,但无读取者 |
SIGALRM |
14 |
退出 |
报警时钟 |
SIGTERM |
15 |
退出 |
来自中止的软件终止信号 |
SIGUSR1 |
16 |
退出 |
用户定义的信号 1 |
SIGUSR2 |
17 |
退出 |
用户定义的信号 2 |
SIGCLD |
18 |
忽略 |
子项状态更改 |
SIGCHLD |
18 |
忽略 |
子项状态更改别名 |
SIGPWR |
19 |
忽略 |
电源故障,重新启动 |
SIGWINCH |
20 |
忽略 |
窗口大小更改 |
SIGURG |
21 |
忽略 |
紧急套接字条件 |
SIGPOLL |
22 |
退出 |
发生了可轮询事件 |
SIGIO |
22 |
退出 |
可能有套接字 I/O |
SIGSTOP |
23 |
停止 |
停止(找不到,也无法忽略) |
SIGTSTP |
24 |
停止 |
来自 tty 的用户停止请求 |
SIGCONT |
25 |
忽略 |
停止的进程已继续 |
SIGTTIN |
26 |
停止 |
已尝试后台 tty 读 |
SIGTTOU |
27 |
停止 |
已尝试后台 tty 写 |
SIGVTALRM |
28 |
退出 |
虚拟计时器已过期 |
SIGPROF |
29 |
退出 |
文件配置计时器已过期 |
SIGXCPU |
30 |
信息转储 |
已超出 cpu 限制 |
SIGXFSZ |
31 |
信息转储 |
已超出文件大小限制 |
SIGWAITINGT |
32 |
忽略 |
进程的 lwp 受阻 |
参见以上内容。
总是执行 signal(sig,SIG_DFL) 的等效函数。
最后一行不需要以换行符结束。
读该流时,所有字符均出现。
空字符不附加至二进制流。
文件位置指示符最初位于文件结尾。
对文本流的写操作不会导致文件在该点之后被截断,除非硬件设备强制这种情况发生。
除标准错误流 (stderr) 之外,输出流在输出至文件时采用缺省缓冲,在输出至终端时采用行缓冲。标准错误输出流 (stderr) 在缺省情况下不缓冲。
缓冲的输出流保存多个字符,然后将这些字符作为块进行写入。未缓冲的输出流将信息排队,以便立即在目标文件或终端上写入。行缓冲的输出将输出的每行排队,直至行完成(请求换行符)时为止。
由于零长度文件有目录项,因此它确实存在。
有效文件名的长度可以为 1 到 1,023 个字符,可以使用除字符 null 和 /(斜杠)之外的所有字符。
同一文件可以多次打开。
在执行关闭文件的最后一个调用时删除文件。程序不能打开已删除的文件。
如果该文件存在,则将其删除,并且新文件改写先前存在的文件。
%p 的输出与 %x 的相同。
%p 的输入与 %x 的相同。
- 字符表示包括边界的范围,因此 [0-9] 与 [0123456789] 等效。
时钟的年代以时钟周期(以程序的起始执行时间为起点)表示。
宿主环境的下列特性特定于语言环境:
特定于语言环境(C 语言环境中无扩展)。
输出总是从左到右进行。
特定于语言环境(在 C 语言环境中为 ".")。
与 4.3.1 相同。
特定于语言环境(C 语言环境中的 ASCII 整理)。
特定于语言环境。下面几个表显示 C 语言环境中的格式。月份名称为:
表 E–9 月份名称
1 月 |
5 月 |
9 月 |
2 月 |
6 月 |
10 月 |
3 月 |
7 月 |
11 月 |
4 月 |
8 月 |
12 月 |
周日期的名称为:
表 E–10 周日期及缩写
日期 |
|
缩写 |
|
星期日 |
星期四 |
日 |
四 |
星期一 |
星期五 |
一 |
五 |
星期二 |
星期六 |
二 |
六 |
星期三 |
三 |
时间的格式为:
%H:%M:%S
日期的格式为:
%m/%d/%y