C语言程序设计 第一章C语言概述.2

来源:互联网 发布:horner算法 编辑:程序博客网 时间:2024/05/29 14:55

C-Based Languages

C has had a huge influence on modern-day programming languages, many of which borrow heavily from it. Of the many C-based languages. several are especially prominent:

C对现代编程语言有着很大的影响,许多优秀的基于C的语言都借鉴于此。


● C++ includes all the features of C, but adds classes and other features to support object-oriented programming.

C++包括了C的所有特性,在此基础上又增加了类和其他特性等支持面向对象。

● Java is based on C++ and therefore inherits many C features.

java在C++的基础上继承了C的特征。

● C# is a more recent language derived from C++ and Java.

C#是一种继承与C++和java的现代语言。

 Perl was originally a fairly simple scripting language; over time it has grown and adopted many of the features of C.

perl刚开始只是简单地脚本语言,随着时间发展已经适应了许多C的特性。


    Considering the popularity of these newer languages, it's logical to ask whether it's worth the trouble to learn C. I think it is. for several reasons. First, learning C can give you greater insight into the features of C++, Java, C#, Perl, and the other C-based languages. Programmers who learn one of these languages first often fail to master basic Features that were inherited from C. Second, there are a lot of older C programs around; you may find yourself needing to read and maintain this code. Third, C is still widely used for developing new software. especially in situations where memory or processing power is limited or where the simplicity of C is desired.

    考虑到当前流行的许多新兴语言,我们很合理的会提出花费精力去学习c是否有必要。我认为是有必要的,有以下几方面原因:第一,学习C语言可以给你提供更好的观点,尤其是面对C++,java,c#,perl以及其他基于C的语言特性时。程序员经常不能掌握继承与C的特性。第二,周围有许多过时的C程序,你有可能需要阅读和维护这些代码。第三,C依然广泛的用于开发新的软件,特别是一些对内存和运行有限制的地方。


    If you haven't already used one of the newer C-based languages, you'II find that this book is excellent preparation for learning these languages. It emphasizes data abstraction. information hiding, and other principles that play a large role in object-oriented programming. C++ includes all the features of C. so you'II be able to use everything you leam from this book if you later tackle C++. Many of the features of C can be found in the other C-based languages as well.


1.2  Strengths and Weaknesses of C

Like any other programming language, C has strengths and weaknesses. Both stem from the language's original use (writing operating systems and other systems software) and its underlying philosophy:

就像任何其他编程语言一样,C语言也有自己的优缺点。两者都源于这种语言预期的用途(编写操作系统和其他系统软件)和语言自身的基础理论体系。


 C is a low-level larrguage.  To serve as a suitable language for systems programming, C provides access to machine-level concepts (bytes and addresses, for example) that other programming languages try to hide. C also provides operations that correspond closely to a computer's built-in instructions, so that programs can be fast. Since application programs rely on it for input/output.storage management, and numerous other services. an operating system can't afford to be slow.

C语言是一种低级语言。作为一种适合系统编程的语言,C语言提供了对机器级概念(例如,字节和地址)的访问,而这些却是其他编程语言试图隐藏的内容。此外,C语言提供了与计算机内在指令紧密协调的操作,使得程序可以快速执行。既然应用程序要依赖操作系统进行输入/输出、存储管理以及其他众多的服务,操作系统一定不能运行得太慢。


  C is a small language. C provides a more limited set of features than many languages. (The reference manual in the second edition of K&R covers the entire language in 49 pages.) To keep the number of features small, C relies

  heavily on a“library" of standard functions. (A "function" is similar to what other programming languages might call a "procedure," "subroutine," or "method.")

C语言是一种小型语言。与许多其他编程语言相比,C语言提供了一套更有限的特性集合。(在K&R第2版的参考手册中仅用49页就描述了整个C语言。)为了保持少量的特性,C语言在很大程度上依赖一个标准函数“库”(“函数”类似于其他编程语言中描述的“过程”或“子程序”)。


 C is permissive language. C assumes that you know what you're doing. so it allows you a wider degree of latitude than many languages. Moreover. C doesn't mandate the detailed error-checking found in other languages.

C语言是一种包容性话言。C语言假设用户知道自己在做什么,因此它提供了比其他许

多语言更广阔的自由度。此外,不同于其他语言的是,C语言不提供详细的查错功能

Strengths

C's strengths help explain why the language has become so popular:

C语言具有的众多优点说明了这种语言如此流行的原因:


Effrciency. Efficiency has been one of C's advantages from the beginning.Because C was intended for applications where assembly language had tradi-tionally been used, it was crucial that C programs could run quickly and inlimited amounts of memory.

高效性。高效性是C语言与生俱来的优点之一。因为C语言原来就用于编写传统的由汇编语言编写的应用程序,所以快速运行并占用有限内存就显得至关重要了。


Portability. Although program portability wasn't a primary goal of C, it has turned out to be one of the language's strengrhs. When a program must run on computers ranging from PCs to supercomputers, it is often written in C. One reason for the portability of C programs is that-thanks to C's early associa-tion with UNIX and the later ANSI/ISO standards-the language hasn't splintered inio incompatible dialects. Another is that C compilers are small and easily written. which has helped make them widely available. Finally, C itself has features that support portability (although there's nothing to prevent programmers from writing nonportable programs).

可移植性。虽然程序的可移植性并不是C语言的主要目标,但是它还是成为了C语言的优点之一。当程序必须在个人计算机到超级计算机这多种机型范围内运行时,常常会用C语言来编写。C程序具有可移植性的一个原因要感谢C语言与UNIX系统的早期结合,以及后来的ANSI/ISO标准化工作。C语言正是由于标准化才没有分裂成不兼容的多种分支。另一个原因是C语言编译器规模小且容易编写,这使得此种编译器得以广泛应用。最后,C语言自身的特性也支持可移植性(尽管它没有阻止程序员编写不具有移植性的程序)。


 Power. C's large collection of data types and operators help make it a powerful language. In C, it's often possible to accomplish quite a bit with just a few lines of code.

功能强大。C语言拥有一个数据类型和运算符的庞大集合,这个集合使得C语言具有强大的表达能力,往往寥寥几行代码就可以实现许多功能。


● Flexibility. Although C was originally designed for systems programming. it has no inherent restrictions that limit it to this arena. C is now used for appli-cations of all kinds, from embedded systems to commercial data processing. Moreover, C imposes very few restrictions on the use of its features; opera-tions that would be illegal in other languages are often permitted in C. For example, C allows a character to be added to an integer value (or, for that matter, a floating-point number). This flexibility can make programming easier,although it may allow some bugs to slip through.

灵活性。虽然C语言最初的设计是为了系统编裎,但是没有固有的约束将它限制在此范围内。C语言现在可以用于编写从嵌入式系统到商业数据处理的各种应用程序。此外,C语言在其特性使用上的限制非常少。在其他语言中认定为非法的操作在C语言中往往是允许的。例如,C语言允许一个字符与一个整数值相加(或者是与一个浮点数相加)。虽然灵活性可能会让某些错误溜掉,但是它却使编程变得更加轻松。


 Standard library. One of C's great strengths is its standard library, which contains hundreds of functions for input/output. string handling, storage allocation. and other useful operations.

C语言的一个突出优点就是它的标准库,包含了数百个函数,这些函数可以用于输入/输出、字符串处理、存储分配以及其他一些实用的操作。


 Integration with UNIX. C is particularly powerful in combination with UNIX (including the popular variant known as Linux). In fact. some UNIX tools assume that the user knows C.

与UNIX系统的集成。C语言在与UNIX系统结合方面特别强大。事实上,一些UNIXI具甚至假定用户是了解C语言的。



上一章C语言程序设计 第一章C语言概述.1