嵌入式开发c语言编译器_嵌入式工程师入门编译与解释语言

嵌入式开发c语言编译器

When observing modern programming languages you can generally group them into one of two categories. Compiled or interpreted.

观察现代编程语言时,通常可以将它们分为两类之一。 编译或解释。

In actuality there is a bit of a blurry line between what is considered a compiled language or an interpreted language. It’s not entirely black and white. For instance, Java toes the line by being compiled into Java bytecode but still executing on the Java Runtime Environment? It’s weird… Python code can also be compiled! However, this article will discuss the differences between compiled and interpreted languages as if they’re distinct.

实际上,在被认为是编译语言或解释语言之间存在一些模糊的界线。 它不完全是黑白的。 例如,Java通过编译成Java字节码而在Java运行时环境上仍在执行,从而使这一行破门而出? 很奇怪…Python代码也可以编译! 但是,本文将讨论编译语言和解释语言之间的区别,好像它们是不同的一样。

As we discussed in the previous chapter of The Embedded Engineer’s Primer, all software run on a modern computer will eventually be translated into the language which processors understand directly; assembly.

正如我们在《嵌入式工程师入门》的上一章中所讨论的那样 ,现代计算机上运行的所有软件最终都将被翻译成处理器可以直接理解的语言。 部件。

The idea of a compiled language is easy. We write our code in C (Or some other compiled language). We compile that code using a compiler (For C, that is usually the gcc compiler). The resulting assembly instructions are saved to a file. That file is then executed by our processor. Done.

编译语言的想法很简单。 我们用C(或其他编译语言)编写代码。 我们使用编译器(对于C语言,通常是gcc编译器)编译该代码。 生成的组装说明将保存到文件中。 该文件然后由我们的处理器执行。 做完了

There’s a bit more captured in an executable file other than simply the instructions of the program. One of these days I’ll break down the anatomy of an executable file! Today is not that day.

除了简单的程序指令之外,可执行文件中还捕获了更多内容。 这些天之一,我将分解可执行文件的结构! 今天不是那天。

But what is an interpreted language?

但是什么是解释语言?

An interpreted language is one in which the source code you write is not directly the source code that is being executed by the processor. You never create a new executable file. Instead, you produce a text file in your chosen language, then provide that text file to an executable (That language’s runtime environment). That executable parses your text file in real-time and then, on your behalf, performs the behavior you requested of the processor after reading each line. For python, that executable is called “python” (obviously).

一种解释语言是您编写的源代码不直接是处理器正在执行的源代码的一种语言。 您永远不会创建新的可执行文件。 相反,您将以您选择的语言生成一个文本文件,然后将该文本文件提供给可执行文件(该语言的运行时环境)。 该可执行文件会实时解析您的文本文件,然后代表您在读取每一行后执行您请求的处理器行为。 对于python,该可执行文件称为“ python”(显然)。

Let’s go back to our Python “Hello, World!” example program from before. However, this time let’s create a file called, myFirstProgram.py and the entirety of that file’s contents will be this one line:

让我们回到我们的Python“ Hello,World!”。 之前的示例程序。 但是,这次我们创建一个名为myFirstProgram.py的文件,该文件的全部内容将是这一行:

print("Hello, World!")

In order to execute this program, we need to call python and provide it our file by executing the following in a command line:

为了执行此程序,我们需要调用python并通过在命令行中执行以下命令来提供文件:

python myFirstProgram.py

The result of running this program will simply be the text “Hello, World!” Notice, python itself is an executable that is parsing your myFirstProgram.py file. If myFirstProgram.py was larger and more than just one line, it would execute line 1 before ever reading line 2.

运行该程序的结果将仅仅是文本“ Hello,World!”。 请注意,python本身是一个可执行文件,可解析myFirstProgram.py文件。 如果myFirstProgram.py较大且不止一行,它将在读取第2行之前执行第1行。

In short, that’s the difference between a compiled and interpreted language. A compiled language is one in which the software you write is directly translated into assembly language and is itself being executed by the processor. An interpreted language has a separate runtime environment. That runtime environment is the executable that is running on the processor. The source code you write is being read and “interpreted” by this runtime environment line by line. Your code simply requests the runtime environment to perform the written behavior on your behalf.

简而言之,那就是编译语言和解释语言之间的区别。 编译语言是将您编写的软件直接翻译成汇编语言并由处理器本身执行的语言。 解释语言具有单独的运行时环境 。 该运行时环境是在处理器上运行的可执行文件。 此运行时环境逐行读取和“解释”您编写的源代码。 您的代码仅要求运行时环境代表您执行书面行为。

Interestingly enough, the python runtime environment is a compiled executable written in C! That fun fact doesn’t actually mean anything for this conversation but… It is interesting. Maybe that’s another discussion we can have about just how pervasive the C programming language actually is. C is so important to software, that even C is written in C!🤯

有趣的是,python运行时环境是用C编写的已编译可执行文件! 这个有趣的事实对于这次对话实际上并没有任何意义,但是……很有趣。 也许那是关于C编程语言实际普及程度的另一次讨论。 C对软件是如此重要,以至于C都是用C编写的! 🤯

但为什么?! (But Why?!)

Now that we’ve defined what an interpreted language is and how they are different from compiled languages. Let’s discuss the several natural questions that you must be thinking about.

既然我们已经定义了什么是解释语言,以及它们与编译语言的区别。 让我们讨论您必须考虑的几个自然问题。

  • Why do multiple languages even exist?

    为什么甚至存在多种语言?
  • What are the advantages/disadvantages of compiled vs interpreted?

    编译和解释的优点/缺点是什么?
  • Which language should I use?!

    我应该使用哪种语言?

为什么甚至存在多种语言? (Why do multiple languages even exist?)

A natural question that many beginner developers have is why are there SO MANY programming languages? If they’re all just listing commands for a processor to execute, why have we not all just agreed that <insert your favorite language here> is the one true language that we should use for EVERYTHING!

许多初学者开发人员自然要解决的问题是,为什么会有那么多编程语言? 如果他们都只是列出要执行的处理器的命令,为什么我们不都同意<insert your favorite language here>是我们应用于一切的一种真正的语言!

As weird as it may sound, there’s a lot of validity to this question. Because, for the most part, any problem which you could possibly imagine is capable of being solved by essentially any programming language. It might be really difficult to do, but it’s likely possible!

听起来很奇怪,但是这个问题有很多道理。 因为在大多数情况下,您基本上可以想象到的任何问题都可以由基本上任何编程语言解决。 这可能确实很难,但是有可能!

Before answering this question, let’s take a step back and comprehend what problem a programming language attempts to solve. All modern programming languages exist to ease the process of human beings explaining problems to a computer. All processors can only perform a short list of tasks. They can add, subtract, store memory, etc… Programming languages simply ease the process of translating abstract concepts that are easy for humans to understand like classes, functions, variables, loops, etc… into a large collection of precise tasks that a processor is capable of executing. There is a massive trade-off between how precise that translation can be versus how easy a programming language is for humans to write. Generally speaking, the easier it is for a human to write behavior in a language, the less efficient the language will be at translating that behavior into instructions on a processor. Different languages make different trade-offs. Python for instance is one of the more simple languages to read and write for humans. However, it is notoriously slow to execute when compared to the same behavior written in C. Python is still plenty fast for simple programs but the more complex your application becomes the more the inefficient performance of python compounds. If you have a large project and strict performance requirements, maybe Python isn’t your best choice.

在回答这个问题之前,让我们退后一步,了解一下编程语言要解决的问题。 存在所有现代编程语言,以简化人类向计算机解释问题的过程。 所有处理器只能执行简短的任务列表。 它们可以增加,减少,存储内存等。编程语言可以简化将人类容易理解的抽象概念(例如类,函数,变量,循环等)转换为处理器所要处理的大量精确任务的过程。能够执行。 在翻译的精确度与编程语言对人类的书写难度之间存在巨大的权衡。 一般而言,人类用一种语言编写行为越容易,该语言将这种行为转换成处理器上的指令的效率就越低。 不同的语言会做出不同的取舍。 例如,Python是人类可以读写的更简单的语言之一。 但是,与用C编写的相同行为相比,它的执行速度出了名的慢。Python对于简单的程序仍然足够快,但是应用程序越复杂,Python化合物的效率就越低。 如果您有一个大型项目并且对性能有严格的要求,那么Python并不是您的最佳选择。

Although, the problem with C is that it is notoriously complicated. Just look at what it takes to write the simplest “Hello, World!” program in C!

虽然,C的问题在于它非常复杂。 只要看看写最简单的“ Hello,World!”所需的内容即可。 用C程序!

#include <stdio.h>int main(int argc, char** argv) {
printf("Hello, World!\n");
return 0;
}

There’s a lot in this source code that doesn’t immediately make sense unless you already understand the C language. Like what is this “int argc, char** argv” nonsense? And why return 0?! But, when you want to write something with strict performance requirements, (Like a video game engine!) you are going to want to use a language that provides the level of control and precision that C or C++ provides.

除非您已经了解C语言,否则此源代码中有很多内容不会立即变得有意义。 像什么“ int argc,char ** argv”胡说? 为什么返回0? 但是,当您要编写具有严格性能要求的内容时(例如视频游戏引擎!),您将要使用一种语言,该语言可以提供C或C ++提供的控制级别和精度。

Each new programming language is usually born from the need for an easier way to translate what humans understand into what computers understand. As we continue to learn about computers and learn how to communicate with people about computers, the vernacular we use changes. And thus, the languages themselves change to ease conveying these new ideas to computers! For example, Apple’s new Swift language was born from the need to more easily convey the ideas required to solve the problems of a modern touch-screen application. Touch screen applications just plain didn’t exist when the original language Apple used, Objective-C, was created. The problems of the future are constantly changing, so the languages we use to describe these new problems are constantly improving. Also, just because a new language comes out does not mean that the old problems or the people who are more comfortable using the old languages immediately go away! And similarly to how it’s difficult to get the whole world to speak English, it’ll be difficult to get the entirety of the software community to use Python. Even though I personally think they should.

通常,每种新的编程语言都源于对将人类的理解转换为计算机的理解的更简便方法的需求。 随着我们继续学习计算机并学习如何与人们交流有关计算机的知识,我们在使用本地语言。 因此,语言本身也发生了变化,以轻松地将这些新思想传达给计算机! 例如,苹果公司新的Swift语言源于更轻松地传达解决现代触摸屏应用程序问题所需的想法的需求。 创建Apple使用的原始语言Objective-C时,不存在普通的触摸屏应用程序。 未来的问题在不断变化,因此我们用来描述这些新问题的语言也在不断改进。 另外,仅仅出现一种新的语言并不意味着旧的问题或更习惯使用旧语言的人们会立即消失! 与使整个世界都很难说英语类似,要让整个软件社区都使用Python也将很困难。 即使我个人认为他们应该。

Keep in mind that as the software community learns more and more about how to best write software, the gap in performance between compiled and interpreted languages is dwindling. Python today is WAY faster than the original python. We’re all still figuring this out! Software as a whole has only existed for ~60 ish years. New problems keep needing new solutions and new languages are constantly improving upon old ideas.

请记住,随着软件社区越来越了解如何最好地编写软件,编译和解释语言之间的性能差距正在缩小。 今天的Python比原始Python快得多。 我们都还在想办法! 整个软件仅存在约60年。 新的问题不断需要新的解决方案,新的语言也在不断改进旧的思想。

口译语言的优势是什么? (What are the advantages of Interpreted Languages?)

  • Portability.

    可移植性。

Portability is an advantage of interpreted languages because the same exact source code, without modification, can be run on any operating system which supports the runtime environment. You can be reasonably assured that you can write your code once, then be able to run it nearly everywhere! That’s powerful.

可移植性是解释语言的优点,因为相同的确切源代码无需修改即可在支持运行时环境的任何操作系统上运行。 您可以放心,您可以编写一次代码,然后几乎可以在任何地方运行它! 真厉害

  • Simplicity.

    简单。

Because the runtime environment handles all of the correspondence with the operating system and the hardware on your behalf, the source code of an interpreted language is capable of being far more simple to read and understand than a compiled language. Simplicity is valuable because it eases the process for people to learn how to be productive in a new language quickly! And with that ease of transition usually comes a larger group of developers actively using the language. Which brings us to the next advantage.

因为运行时环境代表您处理与操作系统和硬件的所有对应关系,所以解释型语言的源代码比编译语言更易于阅读和理解。 简单性很有价值,因为它简化了人们学习新语言的效率的过程! 有了这种轻松的转换,通常会有大量的开发人员积极使用该语言。 这带给我们下一个优势。

  • Community.

    社区。

A large community of developers breeds a healthy environment to solve problems within. The software community is generally quite giving. Many complex solutions to problems are written as free open-source plugins available for you to use in your own projects with free licensing! The larger the community, the more open-source solutions there are for you to build your own projects with. There will also be more 3rd party APIs available and you’ll find more search results when you inevitably need to use Google for help! Writing software, although possible to do alone, is better when done as a team. If you’re a business building your team, you’ll want as large of a pool as possible to choose candidates from.

大量的开发人员会孕育一个健康的环境来解决内部问题。 通常,软件社区相当乐于助人。 许多复杂的问题解决方案都被编写为免费的开源插件,您可以在免费许可的情况下在自己的项目中使用它们! 社区越大,就可以使用更多的开源解决方案来构建自己的项目。 还将提供更多的第三方API,当您不可避免地需要使用Google寻求帮助时,您会发现更多的搜索结果! 编写软件虽然可以单独完成,但如果以团队的形式完成,则更好。 如果您是建立团队的企业,则需要尽可能多的人才库来选择候选人。

口译语言的缺点是什么? (What are the disadvantages of Interpreted Languages?)

  • Performance.

    性能。

As I’ve mentioned before, interpreted languages are generally less efficient at translating the source code you write into instructions on your processor. The mere fact that your source code needs to be read at run-time is itself a hindrance to performance. However, if performance is not a primary requirement then perhaps this disadvantage isn’t very meaningful.

如前所述,在将您编写的源代码转换为处理器上的指令时,解释型语言通常效率较低。 您的源代码需要在运行时读取的事实本身就是性能的障碍。 但是,如果性能不是主要要求,那么此缺点可能就不是很有意义。

  • Lack of Control/Hardware Access.

    缺乏控制/硬件访问。

Another disadvantage is that because interpreted languages aim to be more simplified, they tend to remove the capability to reference specific locations in memory directly. Depending on your project, this could be a limiting factor. There are ways to get around this, usually by creating a custom plugin in C and then calling it from Python, but doing so isn’t always an efficient use of time.

另一个缺点是,由于解释语言的目标是更加简化,因此它们倾向于取消直接引用内存中特定位置的功能。 根据您的项目,这可能是一个限制因素。 有很多方法可以解决此问题,通常是在C中创建一个自定义插件,然后从Python调用它,但这并不总是有效地利用时间。

  • “Magical” behavior.

    “魔术”行为。

The last disadvantage we’ll discuss is more of a personal gripe that I have with using many interpreted languages for production quality projects. The amount of behavior that is abstracted away from you as you write your source code can be difficult to understand in some languages. Due to this lack of understanding of what is happening on your behalf, debugging issues can be difficult. For example, Javascript and web plugins in general fall into this trap often. The frameworks built on top of Javascript perform lots of complex behavior often without explaining what’s actually happening behind the scenes. Debugging is hard when you don’t know what your code is doing.

我们将讨论的最后一个缺点是,在使用许多解释性语言进行生产质量项目时,我会更加个人化。 在某些语言中,编写源代码时从您身上抽象出来的大量行为可能很难理解。 由于对您所发生的事情缺乏了解,因此调试问题可能会很困难。 例如,通常Javascript和Web插件经常会陷入此陷阱。 基于Javascript构建的框架通常执行许多复杂的行为,而没有说明幕后实际发生的情况。 当您不知道代码在做什么时,调试就很困难。

编译语言有哪些优势? (What are the advantages of Compiled Languages?)

  • Speed.

    速度。

Compiled languages generally run much faster than interpreted languages and are more predictable because you generally have to painstakingly explicitly write all your desired behavior. Especially if you’re writing the software for something with high consequences for failure, like a pacemaker or a vehicle. You will want to explicitly know everything that’s happening and when it’s happening.

编译语言的运行速度通常比解释语言要快得多,并且可预测性更高,因为您通常必须尽力而为地明确编写所有所需的行为。 尤其是如果您正在为起故障的高后果的东西(例如起搏器或车辆)编写软件。 您将希望明确地了解正在发生的一切以及何时发生。

  • Direct Access To Memory/Hardware.

    直接访问内存/硬件。

As described earlier. Many interpreted languages completely abstract the hardware away from you so if you require direct access to memory or hardware registers then you may be forced into using a compiled language.

如前所述。 许多解释语言完全将硬件抽象为您,因此,如果您需要直接访问内存或硬件寄存器,则可能会被迫使用编译语言。

  • Less “magic”.

    少“魔术”。

Again, this notion of “magical” behavior is a personal preference. As you may be able to tell by my writing, I enjoy being verbose! Likewise, I enjoy the lack of ambiguity of a compiled language.

同样,“魔术”行为的概念是个人喜好。 如您从我的著作中可以看出的那样,我很喜欢冗长! 同样,我喜欢缺乏一种编译语言的歧义。

  • Stability/Maturity.

    稳定性/成熟度。

Compiled languages are generally much older and thus more stable and mature than many interpreted languages. C for instance has been largely the same for decades and continues to be widely used.

编译语言通常比许多解释语言要古老得多,因此更加稳定和成熟。 例如,C几十年来一直是相同的,并且继续被广泛使用。

编译语言的缺点是什么? (What are the disadvantages of Compiled Languages?)

  • Lack of Portability.

    缺乏便携性。

In order to move between operating systems, your compiled code will usually need to change. Different compilers tend to be slightly different from each other and different operating systems have different requirements that must be satisfied by your source code in order to operate. Generally speaking, if you want your code to run on a wide variety of Operating Systems/hardware, interpreted languages are the most time-efficient option.

为了在操作系统之间移动,通常需要更改已编译的代码。 不同的编译器往往会略有不同,并且不同的操作系统具有不同的要求,您的源代码必须满足这些要求才能进行操作。 一般来说,如果您希望代码在多种操作系统/硬件上运行,则解释型语言是最省时的选择。

  • More obscure problems.

    更晦涩的问题。

Compiled languages, when they fail, often are harder to debug and research what caused the fault. Although more predictable, compiled languages have to deal with errors that are not easily traceable. Specifically, segmentation faults or issues with dereferencing an unintended memory address are difficult errors to debug because neither the compiler nor your operating system/hardware can tell you that you will reference the wrong memory address until you begin executing. You’ll end up with just a vague address out of bounds errors or the subtle behavioral differences that come along with using unintended values. Finding out what went wrong can be frustrating. It happens to the best of us…

编译语言出现故障时,通常更难以调试和研究导致故障的原因。 尽管更可预测,但编译语言必须处理不易追踪的错误。 特别是,分段错误或与取消引用意外的内存地址有关的问题是难以调试的错误,因为编译器和操作系统/硬件都无法告诉您在开始执行之前,您将引用错误的内存地址。 您最终只会得到一个模糊的地址,超出范围的错误或使用意外值所带来的细微的行为差异。 找出出了什么问题可能令人沮丧。 碰巧是我们最好的...

我应该使用哪种语言? (Which language should I use?!)

Unfortunately, I can’t just give a direct answer on which language or which type of language you should use without having an understanding of the problem you’re attempting to solve. For the most part, popularity is the largest determining factor when I choose a new language for myself. Whichever language the most people use to solve similar problems to the problem I’m attempting to solve will always be my top choice. Because with popularity comes community and communities drive the creation of information and resources. The second most useful factor in my opinion is how well the documents of a language are organized. If I can navigate the official documentation for a language easily then that’s a huge bonus in my eyes.

不幸的是,我不能直接给出关于应该使用哪种语言或哪种类型的语言的直接答案,而又不了解您要解决的问题。 在大多数情况下,当我为自己选择一种新语言时,人气是最大的决定因素。 大多数人用来解决与我要解决的问题类似的问题的语言始终是我的最佳选择。 因为随着社区的普及,社区和社区推动了信息和资源的创建。 我认为第二个最有用的因素是一种语言的文档的组织程度。 如果我可以轻松浏览某种语言的官方文档,那对我来说是一个巨大的收获。

Overall, your choice of language doesn’t really matter all that much. What matters is your ability to create what you set out to create! If you’re ever uncertain about which way you should go, just choose something. Anything! Just starting is more important than wasting a ton of time figuring out how to start.

总体而言,您对语言的选择并不重要。 重要的是您有能力创造自己打算创造的东西! 如果您不确定应该走哪条路,那就选择一些东西。 随便啦! 刚开始比浪费大量时间弄清楚如何开始更重要。

翻译自: https://medium.com/@mquettan/the-embedded-engineers-primer-compiled-vs-interpreted-languages-89452834381d

嵌入式开发c语言编译器

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值