IE盒子

搜索
查看: 98|回复: 7

为什么学习c语言?

[复制链接]

3

主题

3

帖子

9

积分

新手上路

Rank: 1

积分
9
发表于 2023-3-3 14:58:35 | 显示全部楼层 |阅读模式

维基百科在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而不是其他高级语言都是一个意见问题,技术和业务要求都可以决定所需的语言。


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.



欢迎关注微信公众号-嵌入式Linux
觉得不错,请帮忙转发,点赞,您的每一次支持,我都将铭记于心
回复

使用道具 举报

2

主题

5

帖子

7

积分

新手上路

Rank: 1

积分
7
发表于 2023-3-3 14:58:48 | 显示全部楼层
相对 Java 、python 开发周期还是比较慢的,要求功底比较高
回复

使用道具 举报

2

主题

4

帖子

8

积分

新手上路

Rank: 1

积分
8
发表于 2023-3-3 14:59:19 | 显示全部楼层
谢谢大神回复,已到家
回复

使用道具 举报

3

主题

10

帖子

15

积分

新手上路

Rank: 1

积分
15
发表于 2023-3-3 14:59:35 | 显示全部楼层
你这个人怎么那么喜欢打官腔啊
回复

使用道具 举报

4

主题

11

帖子

19

积分

新手上路

Rank: 1

积分
19
发表于 2023-3-3 15:00:02 | 显示全部楼层
这几年,在北京和上海闯来闯去,原本内向型人格的我,做事风格也逐渐变得风风火火,在高强度快节奏下像个工作机器,不带一丝情感绝对执行工作计划。

无论是互联网圈,还是科研圈,这两圈子的码农各个都能独挡一面,久而久之,我认识了太多优秀的码农,然后,我发现一个残酷的共同点——
他们都不舍得用内存。

作者:Waiter
链接:https://zhuanlan.zhihu.com/p/36630576
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
回复

使用道具 举报

1

主题

6

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2023-3-3 15:00:17 | 显示全部楼层
知道为什么Linux之父炮轰C++吗?
回复

使用道具 举报

1

主题

4

帖子

4

积分

新手上路

Rank: 1

积分
4
发表于 2023-3-3 15:00:40 | 显示全部楼层
我不认为这个是官腔,知识拿出来让大家知道而已,可以有不同的意见,就像linux之父不喜欢C++一样,也许C++有罪,但也不至于罪以致死。
回复

使用道具 举报

3

主题

8

帖子

14

积分

新手上路

Rank: 1

积分
14
发表于 2023-3-3 15:01:12 | 显示全部楼层
我想问下,C语言在高性能程序开发会被其他语言取代吗?比如,rust。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表