什么是C标准


前言

本文主要回答下面几个问题,算是最基础的扫盲科普文

  • 什么是C标准?

什么是C标准?

一流企业卖标准,二流企业卖专利,三流企业卖产品。
                                                                            —某抖音销售鸡汤文

看到“标准”这个词,正常人脑海当中首先想到两个问题:

  • 1、这是什么东西用的标准?吃饭的标准,还是接待的标准
  • 2、都标准了些什么东西?一顿饭只准四菜一汤,还是住宿标间不能超过20m2

下面直接贴上《C标准库》里面对于C标准的表述

Dennis Ritchie developed the original version of the programming IanguageC at AT&T Bell Laboratories in the early 1970s. At first it appeared to be little more than a UNIX-specific system-implementation language for the DEC PDP-11 computer architecture. Others soon discovered, however, that it modeled a broad class of modern computers rather well. By the late 1970s, several other compiler writers had implemented C for a variety of popular targets, from microcomputers to mainframes. By the early 1980s, hundreds of implementations of C were being used by a rapidly growing community of programmers. It was time to standardize the language.
standards The American National Standards Institute, or ANSI, standardizes computer programming languages in the United States. X3Jll is the name of the ANSI-authorized committee that developed the standard for C, starting in 1983. The language is now defined by ANSI Standard X3.159-1989.
The International Standards Organization, or KO, C has a similar responsibility in the international arena. IS0 formed the technical committee JTCl/SC22/WG14 to review and augment the work of X3Jll. Currently,IS0 has adopted a standard for C that is essentially identical to X3.159. It is called IS0 9899:1990. The C Standards differ only in format and in the numbering of sections. The wording differs in a few small places but makes no substantive change to the language definition.

简单概括一下,在1970年代早期,Dennis Ritchie在美国贝尔实验室开发出了C语言的最初版本,人们把这个版本的C语言称为叫“K&R C”,他是C语言的一个实验室雏形,是一个非正式标准。后来的一段时间,C语言被广泛使用,然而由于“K&R C”标准对C语言的规范不够清晰,甚至存在某些缺陷,导致各种开发工具和库存在兼容性问题,甚至出现了“方言”,到了20世纪70年代末,在各类流行的计算机上出现了C编译器的不同版本。后来为了更好地规范C语言,1989年,美国国家标准学会(ANSI)推出了ANSI C89版标准,他对最初的实验室“K&R C”进行了一些修正。
 简单举个例子(来自知乎):

//ANSI C89 函数声明,必须指明函数的参数
int foo(int num, char ch);
//or
int foo(int, char);

//K&R C   函数声明,不需要指明明函数的参数
foo();

与之类似,国际标准化组织(ISO)也开始在国际范围内制定C语言的标准,1990年也推出了他们的的C语言标准——ISO C90;实质上,ISO C90ANSI C89 是同一个规范。因为ISO采纳了ANSI C89标准。由于ANSI早于ISO推出,因此人们通常称这个版本的C为ANSI C 89或者C89。再后来,ANSI 和 ISO 联合在1999年又推出了 C99标准,增加了对C语言国际化的支持。
现在来回答上面提出的两个问题,C标准,见名知意,就是C语言的使用的标准,该标准的作用是,规范了该怎么用C语言写代码。只有遵循这套标准写出来的代码,才能被遵循C标准的编译器“翻译”成CPU能看懂的机器语言。否则的话,遵循C标准的编译器就会报错,更不用提CPU运行了。基本就是下图这种情况:
在这里插入图片描述
这时候又产生了一个疑问,这么干的好处是什么?大家各自方言都用的很欢乐,你为啥要给统一了?老外不是一直喜欢自由吗?个人认为C语言属于一种高级语言,需要相应的编译器给翻译成CPU能看懂的机器码来执行程序,如果C语言标准无法统一,相应的C编译器就没法统一,那么高级语言的源码可移植性就无从谈起。

总结

提示:这里对文章进行总结:

以下归纳来自知乎,所谓标准C,包括三大块:
1.当然就是那份 ANSI C标准了。此标准,最早的一个经典版是我们大家都熟知的C89,此后出现了C99,C10,C11等;
2.一个符合ANSI C标准的 C编译器;
3.一个满足ANSI C标准的 C标准库,最佳开源实例,上述提到的 glibc;(后续文章会谈到)
用一幅图总结一下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值