简体   繁体   English

与 c 相比,为什么开发人员在嵌入式系统中使用 c/c++ 而不是像 python 这样的高级语言?

[英]why developers use c/c++ for embedded systems rather than high level language like python compared to c?

can we access memory via python like we do in c/c++?我们可以像在 c/c++ 中那样通过 python 访问 memory 吗? Have been programming in c for a while and came across this question?已经在 c 编程了一段时间,遇到了这个问题? I see that over 90 percent of the code is written in c/c++ for embedded systems我看到超过 90% 的代码是用 c/c++ 为嵌入式系统编写的

why developers use c/c++ for embedded systems rather than high level language like python compared to c?与 c 相比,为什么开发人员在嵌入式系统中使用 c/c++ 而不是像 python 这样的高级语言?

The answer to this is most certainly partially historical.这个问题的答案肯定是部分历史的。

C was originally designed to be used for operating systems : C 最初设计用于操作系统

Initially, C language was developed to be used in UNIX operating system.最初,C 语言被开发用于 UNIX 操作系统。 It inherits many features of previous languages such as B and BCPL.它继承了以前语言如 B 和 BCPL 的许多特性。

I would imagine this had a lot to do with its use in embedded systems.我想这与它在嵌入式系统中的使用有很大关系。

C++, on the other hand, was derived from C :另一方面, C++ 是从 C 派生的

In 1979, Bjarne Stroustrup, a Danish computer scientist, began work on "C with Classes", the predecessor to C++.[15] 1979 年,丹麦计算机科学家 Bjarne Stroustrup 开始研究“C with Classes”,这是 C++ 的前身。 [15] The motivation for creating a new language originated from Stroustrup's experience in programming for his PhD thesis.创建新语言的动机源于 Stroustrup 博士论文的编程经验。 Stroustrup found that Simula had features that were very helpful for large software development, but the language was too slow for practical use, while BCPL was fast but too low-level to be suitable for large software development. Stroustrup 发现 Simula 的特性对大型软件开发很有帮助,但语言速度太慢,不适合实际使用,而 BCPL 速度快但级别太低,不适合大型软件开发。 When Stroustrup started working in AT&T Bell Labs, he had the problem of analyzing the UNIX kernel with respect to distributed computing.当 Stroustrup 开始在 AT&T 贝尔实验室工作时,他遇到了在分布式计算方面分析 UNIX kernel 的问题。 Remembering his Ph.D.记住他的博士学位。 experience, Stroustrup set out to enhance the C language with Simula-like features.[16]根据经验,Stroustrup 着手增强 C 语言的类似 Simula 功能。[16] C was chosen because it was general-purpose, fast, portable and widely used.选择 C 是因为它通用、快速、便携且应用广泛。 As well as C and Simula's influences, other languages also influenced this new language, including ALGOL 68, Ada, CLU and ML.除了 C 和 Simula 的影响之外,其他语言也影响了这种新语言,包括 ALGOL 68、Ada、CLU 和 ML。

Initially, Stroustrup's "C with Classes" added features to the C compiler, Cpre, including classes, derived classes, strong typing, inlining and default arguments.[17]最初,Stroustrup 的“C with Classes”为 C 编译器 Cpre 添加了特性,包括类、派生类、强类型、内联和默认 arguments。 [17]

In 1982, Stroustrup started to develop a successor to C with Classes, which he named "C++" (++ being the increment operator in C) after going through several other names. 1982 年,Stroustrup 开始使用 Classes 开发 C 的继任者,在经历了几个其他名称之后,他将其命名为“C++”(++ 是 C 中的增量运算符)。 New features were added, including virtual functions, function name and operator overloading, references, constants, type-safe free-store memory allocation (new/delete), improved type checking, and BCPL style single-line comments with two forward slashes (//).添加了新功能,包括虚函数、function 名称和运算符重载、引用、常量、类型安全的自由存储 memory 分配(新/删除)、改进的类型检查和带有两个正斜杠的 BCPL 样式单行注释(/ /)。 Furthermore, Stroustrup developed a new, standalone compiler for C++, Cfront.此外,Stroustrup 为 C++、Cfront 开发了一个新的独立编译器。

Consequently, while the languages have now significantly diverged, they were very similar to each other.因此,虽然语言现在已经显着不同,但它们彼此非常相似。

Python , on the other hand, was designed to be used with operating systems, not to create them:另一方面, Python旨在操作系统一起使用,而不是创建它们:

The programming language Python was conceived in the late 1980s, 1 and its implementation was started in December 1989 2 by Guido van Rossum at CWI in the Netherlands as a successor to ABC capable of exception handling and interfacing with the Amoeba operating system.编程语言 Python 是在 1980 年代后期构思的, 1并于 1989 年 12 月2由荷兰 CWI 的 Guido van Rossum 开始实施,作为 ABC 的继承者,能够处理异常并与 Amoeba 操作系统交互。

Languages like Python are run through interpretation, which means that you would need another software in between your hardware and your program to read it. Python 之类的语言是通过解释运行的,这意味着您需要在硬件和程序之间使用另一个软件来读取它。

On the other hand, languages like C or C++ are compiled into machine codes, so that the machine can read them directly.另一方面,像 C 或 C++ 这样的语言被编译成机器码,机器可以直接读取它们。

And since you asked about memory management, Python does not give you precise memory management, where as C or C++ does. And since you asked about memory management, Python does not give you precise memory management, where as C or C++ does.

Cost.成本。

It costs more to have a platform that can run a python program in the python VM verses one that runs natively compiled applications.拥有一个可以在 python VM 中运行 python 程序的平台比运行本机编译的应用程序的平台成本更高。

Manipulation of memory directly is difficult via python which is very much required for embedded systems programming at certain use cases.通过 python 直接操作 memory 是很困难的,这在某些用例中是嵌入式系统编程非常需要的。

Also, a garbage collector is occassionally run in python that finds unused memory objects and frees them.此外,偶尔会在 python 中运行垃圾收集器,以查找未使用的 memory 对象并释放它们。 It should be noted that it may sometime consume more time than expected on garbage collection.应该注意的是,有时它在垃圾收集上可能会花费比预期更多的时间。

A typical realtime embedded systems expects faster execution at predictable time.典型的实时嵌入式系统期望在可预测的时间更快地执行。 C,C++ provide faster execution speed and good control over memory that is required for a typical embedded system. C,C++ 提供更快的执行速度和对典型嵌入式系统所需的 memory 的良好控制。 Hence python is mostly not considered in such cases.因此 python 在这种情况下大多不被考虑。

I'd argue that the embedded space is using Python.我认为嵌入式空间正在使用 Python。 CircuitPython and MicroPython are both versions of Python that are specifically designed for use on embedded systems. CircuitPythonMicroPython都是 Python 的两个版本,专门设计用于嵌入式系统。 Sure, C and C++ are still very popular, but Python is definitely gaining traction.当然,C 和 C++ 仍然很受欢迎,但 Python 肯定会受到关注。

At this point in time, most every microcontroller board available from Adafruit has a port of one of those two Python systems available for it.目前, Adafruit提供的大多数微控制器板都有一个可用的两个 Python 系统之一的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM