B语言的起源?
B语言最早是Ken Thompson 和 Dennis Ritchie 于 1969 年左右在贝尔实验室开发的一种编程语言,主要基于BCPL语言,当时Thompson在Mulcs项目中使用的语言。
New B语言的故事
B语言最早用于PDP-7等一些老式固定类型的电子设备上没有问题,但在PDP-11上却是个令人头疼的事情,因为它有不同的类型。Ritchie从1971年开始着手加入有类型,逐渐变成了所谓的"New B"语言,很快就变成如今所讲的C语言。事实上,在B语言之前,例如Fortran就有类型系统,只不过C语言又将类型系统加到B语言上,解决当时系统遇到的问题。
B语言代码实例
如下是Ken Thompson的Users' Reference to B的示例代码,和C语言很接近了。
/* The following program will calculate the constant e-2 to about
4000 decimal digits, and print it 50 characters to the line in
groups of 5 characters. The method is simple output conversion
of the expansion
1/2! + 1/3! + ... = .111....
where the bases of the digits are 2, 3, 4, . . . */
main() {
extrn putchar, n, v;
auto i, c, col, a;
i = col = 0;
while(i<n)
v[i++] = 1;
while(col<2*n) {
a = n+1;
c = i = 0;
while (i<n) {
c =+ v[i] *10;
v[i++] = c%a;
c =/ a--;
}
putchar(c+'0');
if(!(++col%5))
putchar(col%50?' ': '*n');
}
putchar('*n*n');
}
v[2000];
n 2000;
若文章对您有帮助,欢迎关注。助您在编程路上越走越好!
微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。
我是程序员小迷(致力于C、C++、Java、Kotlin、Android、iOS、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。