为什么学习c语言?

维基百科 C(编程语言)中 有相关信息

C 是编写 操作系统 最常用的编程语言。用C编写的第一个操作系统是 Unix 。后来的操作系统如 GNU / Linux 都是用C语言编写的.C不仅是操作系统的语言,它还是当今几乎所有最流行的高级语言的前身和灵感。事实上, Perl PHP Python Ruby 都是用C语言编写的。

通过类比,假设您将学习西班牙语,意大利语,法语或罗马尼亚语。你认为懂拉丁语对你有帮助吗?正如拉丁语是所有这些语言的基础一样,了解C将使您能够理解和欣赏基于C传统的整个编程语言系列.C的知识可以实现自由。

为什么是C,而不是汇编语言?[   编辑 ]

虽然 汇编语言 可以提供程序的速度和最大程度的控制,但C提供了可移植性。

不同的处理器使用不同的汇编语言进行编程,只能选择和学习其中一种处理器过于随意。事实上,C的主要优势之一是它结合了各种计算机体系结构的通用性和可移植性,同时保留了汇编语言提供的大部分硬件控制。

例如,可以在HP 50g计算器( ARM 处理器),TI-89计算器( 68000 处理器),Palm OS Cobalt智能手机(ARM处理器),原始iMac( PowerPC ),Arduino( Atmel )上编译和运行C程序。 AVR )和Intel iMac( Intel  Core 2 Duo)。这些设备中的每一个都有自己的汇编语言,与任何其他设备的汇编语言完全不兼容。

装配虽然功能非常强大,但是编写大型应用程序并且难以以合理的方式进行读取或解释时非常困难。C是一种编译语言,可以创建快速有效的可执行文件。它也是一个小的“你看到的就是你得到的”语言:C语句最多只对应少数汇编语句,其他一切都由库函数提供。

那么,C在全世界中占领鳌头,你还有什么奇怪的呢?

就像推翻多米诺骨牌一样,下一代计划也跟随其祖先的潮流。用C设计的操作系统总是有用C语言设计的系统库。这些系统库反过来用于创建更高级的库(如 OpenGL GTK ),这些库的设计者经常决定使用系统库使用的语言。 。应用程序开发人员使用更高级别的库来设计文字处理器,游戏,媒体播放器等。他们中的许多人会选择使用上级图书馆使用的语言进行编程。这种模式一直在继续......

为什么是C,而不是另一种语言?[   编辑 ]

C的主要设计是生成可移植代码,同时保持性能并最小化占用空间( CPU时间 内存 使用,磁盘I / O等)。这对于 操作系统 嵌入式系统 或性能很重要的其他程序(“高级”接口会影响性能)非常有用。使用C,可以相对容易地保持对给定行真正做的事情的心理描述,因为大多数事情都是在代码中明确写出来的。C为低级应用程序提供了很大的代码库。它是 UNIX 的“本机”语言,使其具有灵活性和可移植性。它是一种稳定而成熟的语言,不太可能在很长一段时间内消失,并且已被移植到大多数(如果不是全部)平台。

一个有力的原因是内存分配。与大多数编程语言不同,C允许程序员直接写入内存。C中的关键结构(如结构,指针和数组)旨在以高效,与机器无关的方式构造和操作内存。特别是,C可以控制数据结构的内存布局。此外,动态内存分配在程序员的控制之下(这也意味着内存释放必须由程序员完成)。像 Java 和Perl 这样的语言使程序员不必管理内存分配和指针的大部分细节( 内存泄漏 除外)和一些其他形式的超额内存使用)。这很有用,因为在构建高级程序时处理内存分配是一个高度容易出错的过程。但是,在处理低级代码(例如控制设备的操作系统部分)时,C提供了统一,干净的界面。大多数其他语言都不存在这些功能。

虽然Perl,PHP,Python和Ruby可能功能强大,并且支持C中默认未提供的许多功能,但它们通常不是用自己的语言实现的。相反,大多数此类语言最初依赖于使用C(或其他高性能编程语言)编写,并且需要将它们的实现移植到新平台才能使用它们。

与所有编程语言一样,无论您是否想要选择C而不是其他高级语言都是一个意见问题,技术和业务要求都可以决定所需的语言。


v2-5d273397d5426c63617051dc2cce2a4e_hd.jpg

Wikipedia  has related information at  C (programming language)

C  is the most commonly used programming language for writing  operating systems . The first operating system written in C is  Unix . Later operating systems like  GNU/Linux  were all written in C. Not only is C the language of operating systems, it is the precursor and inspiration for almost all of the most popular high-level languages available today. In fact,  Perl PHP Python  and  Ruby  are all written in C.

By way of analogy, let's say that you were going to be learning Spanish, Italian, French, or Romanian. Do you think knowing Latin would be helpful? Just as Latin was the basis of all of those languages, knowing C will enable you to understand and appreciate an entire family of programming languages built upon the traditions of C. Knowledge of C enables freedom.

Why C, and not assembly language?[ edit ]

While  assembly language  can provide speed and maximum control of the program, C provides portability.

Different processors are programmed using different Assembly languages and having to choose and learn only one of them is too arbitrary. In fact, one of the main strengths of C is that it combines universality and portability across various computer architectures while retaining most of the control of the hardware provided by assembly language.

For example, C programs can be compiled and run on the HP 50g calculator ( ARM  processor), the TI-89 calculator ( 68000  processor), Palm OS Cobalt smartphones (ARM processor), the original iMac ( PowerPC ), the Arduino ( Atmel AVR ), and the Intel iMac ( Intel  Core 2 Duo). Each of these devices has its own assembly language that is completely incompatible with the assembly language of any other.

Assembly, while extremely powerful, is simply too difficult to program large applications and hard to read or interpret in a logical way. C is a compiled language, which creates fast and efficient executable files. It is also a small “what you see is all you get” language: a C statement corresponds to at most a handful of assembly statements, everything else is provided by library functions.

So is it any wonder that C is such a popular language?

Like toppling dominoes, the next generation of programs follows the trend of its ancestors. Operating systems designed in C always have system libraries designed in C. Those system libraries are in turn used to create higher-level libraries (like  OpenGL , or  GTK ), and the designers of those libraries often decide to use the language the system libraries used. Application developers use the higher-level libraries to design word processors, games, media players and the like. Many of them will choose to program in the language that the higher-level library uses. And the pattern continues on and on and on...

Why C, and not another language?[ edit ]

The primary design of C is to produce portable code while maintaining performance and minimizing footprint ( CPU time memory  usage, disk I/O, etc.). This is useful for  operating systems embedded systems  or other programs where performance matters a lot (“high-level” interface would affect performance). With C it’s relatively easy to keep a mental picture of what a given line really does, because most of the things are written explicitly in the code. C has a big codebase for low level applications. It is the “native” language of  UNIX , which makes it flexible and portable. It is a stable and mature language which is unlikely to disappear for a long time and has been ported to most, if not all, platforms.

One powerful reason is memory allocation. Unlike most programming languages, C allows the programmer to write directly to memory. Key constructs in C such as structs, pointers and arrays are designed to structure and manipulate memory in an efficient, machine-independent fashion. In particular, C gives control over the memory layout of data structures. Moreover dynamic memory allocation is under the control of the programmer (which also means that memory deallocation has to be done by the programmer). Languages like  Java  and Perl shield the programmer from having to manage most details of memory allocation and pointers (except for  memory leaks  and some other forms of excess memory usage). This can be useful since dealing with memory allocation when building a high-level program is a highly error-prone process. However, when dealing with low-level code such as the part of the OS that controls a device, C provides a uniform, clean interface. These capabilities just do not exist in most other languages.

While Perl, PHP, Python and Ruby may be powerful and support many features not provided by default in C, they are not normally implemented in their own language. Rather, most such languages initially relied on being written in C (or another high-performance programming language), and would require their implementation be ported to a new platform before they can be used.

As with all programming languages, whether you want to choose C over another high-level language is a matter of opinion and both technical and business requirements could dictate which language is required.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31561984/viewspace-2221107/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31561984/viewspace-2221107/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值