c99标准与c89标准的主要区别

来源:互联网 发布:文字江湖 源码 编辑:程序博客网 时间:2024/05/21 10:30

restricted character set support via digraphs and <iso646.h>

通过双字符和<iso646.h>头文件支持限定字符集

 

wide character library support in <wchar.h> and <wctype.h>

支持宽字符的<wchar.h><wctype.h>函数库

 

more precise aliasing rules via effective type

通过有效类型定义更准确的别名规则

 

restricted pointers

受限指针

如果指针p指向对象在之后需要修改,该对象不会允许通过除指针p之外的任何方式访问

比如在c99之前,memcpy函数定义是memcpy(void *s1, const void *s2, size_t n);,执行时有可能s1s2所指向的区域有重叠而造成执行结果错误,而c99memcpy函数的定义改为memcpy(void *restrict s1, const void restrict s2, size_t n),则s1s2指向的区域就不能有重叠,否则函数不能保证能够执行

 

variablelength arrays

可变长数组

int n;

scanf(“%d”, &n);

int a[n];   //可变长数组

 

 

?exible array members

灵活数组成员

允许结构的最后一个成员是长度为零的数组,如char chars[];。这种结构一般用作访问 malloc 内存的头文件。如:

struct vstring{

         Int len;

         char chars[];    //灵活数组成员,

};

Char数组的长度在vstring结构分配内存时确定

Struct vstring *str = malloc(sizeof(struct vstring) + n));

str->len = n;

 

static and type quali?ers in parameter array declarators

可以用static和类型限定符声明数组参数

Int a[static 3];

 

complex (and imaginary) support in <complex.h>

<complex.h>中支持复数(和虚数)

 

typegeneric math macros in <tgmath.h>

<tgmath.h>中支持泛型数学

<tgmath.h>提供了带参数的宏,宏的名字与<math.h><complex.h>中的函数名相匹配,这些泛型宏可以检测参数的类型,然后调用<math.h><complex.h>中相应的函数

 

the long long int type and library functions

long long int类型及库函数

 

increased minimum translation limits

提高最小编译限制

限制

C89标准

C99标准

数据块的嵌套层数

15

127

条件语句的嵌套层数

8

63

内部标识符中的有效字符个数

31

63

外部标识符中的有效字符个数

6

31

结构或联合中的成员个数

127

1023

函数调用中的参数个数

31

127

 

additional ?oatingpoint characteristics in <float.h>

<float.h>中增加浮点类型特性

 

remove implicit int

不再隐式声明为int类型

 

reliable integer division

更准确的整型除法

C89i/j的两个整数操作数中有负数时,除法的结果既可以向上取整,也可以向下取整,在C99中总是向0取整。C89中如果ij为负数,i%j结果与实现有关,在c99中结果符号总与i的符号相同

 

universal character names (/u and /U)

通用字符名

UCS的码值可以在www.unicode.org/charts/找到

 

extended identi?ers

扩大标识符范围

大部分通用字符名都可以用于标识符,且c99要求编译器至少能区分标识符的前63个字符

 

hexadecimal ?oatingpoint constants and %a and %A printf/scanf conversion speci?ers

printf/scanf中十六进制浮点常量的转换说明符

 

compound literals

复合字面量

(int[]){3,0,3,4,1};

 

designated initializers

指定初始化

Int a[15] = {[14] = 48, [9] = 7, [2] = 29};

 

// comments

//注释

 

extended integer types and library functions in <inttypes.h> and <stdint.h>

<inttypes.h><stdint.h>中扩展整数类型的库函数

扩展类型

含义

int16_t

整数长度为精确16

int_least16_t

整数长度为至少16

int_fast32_t

最稳固的整数类型,其长度为至少32

intmax_t

最大整数类型

uintmax_t

最大无符号整数类型

 

remove implicit function declaration

不支持隐式声明函数

 

preprocessor arithmetic done in intmax_t/uintmax_t

用最大宽度整数类型来预处理算术运算

 

 

mixed declarations and code

允许代码段与声明混合

允许在程序块中任何地方声明变量,只要在第一次调用该变量之前

 

new block scopes for selection and iteration statements

给选择语句和迭代语句新的代码块作用域

选择语句(if,switch)和循环语句(while, do, for)及所控制的内部也被视为块

 

integer constant type rules

新的整型常量规则

 

integer promotion rules

新的整型提升规则

 

vararg macros

可变参数宏

#define debug(...) fprintf(stderr, __VA_ARGS__)

#define showlist(...) puts(#__VA_ARGS__)

#define report(test, ...) ((test)?puts(#test): printf(__VA_ARGS__))

debug(“Flag”);

debug(“X = %d/n”,x);

showlist(The first, second, and third items.);

report(x>y, “x is %d but y is %d”, x, y);

预处理后变为

fprintf(stderr, “Flag”);

fprintf(stderr, “X = %d/n”, x);

puts(“The first, second, and third items.”);((x>y)?puts(“x>y”):printf(“x is %d but y is %d”, x, y));

 

the vscanf family of functions in <stdio.h> and <wchar.h>

<stdio.h><wchar.h>中支持vscanf族函数

 

additional math library functions in <math.h>

<math.h>中增加数学库函数

 

?oatingpoint environment access in <fenv.h>

<fenv.h>中使用标准的浮点环境

 

IEC 60559 (also known as IEC 559 or IEEE arithmetic) support

支持 IEEE浮点标准

 

trailing comma allowed in enum declaration

允许枚举类型有尾逗号

enum gray_values{

         BLACK = 0,

         GARK_GRAY = 64,

         GRAY = 128,

         LIGHT_GRAY = 192,

};

 

%lf conversion speci?er allowed in printf

printf中允许%lf转换说明符

 

inline functions

内联函数

 

the snprintf family of functions in <stdio.h>

<stdio.h>中定义了snprintf族函数

 

boolean type in <stdbool.h>

<stdbool.h>中定义boolean类型

 

idempotent type quali?ers

幂等限定符

如果同一限定符在同一说明符限定符列表中出现多次(无论直接出现还是通过一个或多个 typedef),行为与该类型限定符仅出现一次时相同。

const const int i = 0;         const int i = 0 相同

 

empty macro arguments

空宏参数

C99允许宏调用中任意或所有参数为空。

#define ADD(x,y) (x+y)

x = ADD(j,k);

y = ADD(,k);

预处理后变为

X = (j+k);

Y = (+k);

 

#define JOIN(x,y,z) x##y##z

Int JOIN(a,b,c), JOIN(a,b,), JOIN(a,,c), JOIN(,,c)

预处理后变为

Int abc, ab, ac, c;

 

new struct type compatibility rules

新的结构体兼容规则

C89中,对于不同文件定义的结构来说,如果它们的成员具有相同的名字且顺序一样,则为兼容的,C99还要求两个结构要么具有相同的标记,要么都没有

 

additional prede?ned macro names

新增预定义宏名

 

_Pragma preprocessing operator

_pragma预处理运算符

_Pragma(“data(heap_size => 1000, stack_size => 2000)”)

#pragma data(heap_size => 1000, stack_size => 2000)

是一样的

 

standard pragmas

标准编译提示

CX_LIMITED_RANGE

FENV_ACCESS

FP_CONTRACT

 

_ _func_  _ prede?ned identi?er

__func__预定义标识符

编译器支持预定义标识符 __func____func__ 定义为字符数组,它包含 __func__ 所在的当前函数的名称。

 

VA_COPY macro

VA_COPY

用于复制可变参数列表

 

additional strftime conversion speci?ers

增加strftime转换说明符

 

LIA compatibility annex

LIA标准的兼容附录

 

deprecate ungetc at the beginning of a binary ?le

不支持在二进制文件开始处使用ungetc

 

remove deprecation of aliased array parameters

 

 最后这个不懂是什么意思~~~

 

原创粉丝点击