Arduino 是否完全支持 C++ 标准库? [英] Is the C++ Standard Library fully supported on Arduino?

查看:118
本文介绍了Arduino 是否完全支持 C++ 标准库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是询问 ,而是询问用于微控制器的标准库作为一个整体.

Not asking about <string> but about the Standard-Library as a whole for use on micro-controllers.

我还没有 Arduino 板来执行代码,正如标题所说,我很好奇 C++ 标准库是否在 Arduino 上得到完全支持并且已经成为 Arduino IDE 的一部分.毋庸置疑,标准库可能是最高效、经过全面测试且资源最少的公开可用 C++ 代码,并且可以让为 Arduino 等微控制器编写代码变得更加容易.

I don't yet own an Arduino board to execute code on, and as the title says, I'm curious if the C++ Standard-Library is fully supported on Arduino and already part of the Arduino IDE. It really goes without saying that the Standard-Library is probably the most efficient, fully tested, and resource-minimal publicly available C++ code out there, and would make life much easier to code for micro controllers like Arduino.

或者,我是否以某种方式错过了 Arduino/微控制器?那,因为他们的资源如此有限,大多数代码必须完全针对特定功能量身定制,而不是通用或模板化?

Or, am I missing the point of Arduino/micro-controllers somehow? That, because their resources are so limited, most code has to be completely tailored to a specific function, and not generic or templatized?

如果标准库不是 Arduino IDE 的一部分,那么我如何包含特定的库,例如 ?

If the Standard-library is not a part of Arduino IDE, then how can I include specific libraries such as <algorithm> and <bitset>?

推荐答案

Arduino 与其他嵌入式系统项目有很大不同.一方面,它使用自己的基于 C/C++ 的语言.另一方面,您正在处理令人难以置信的专业软件,您不太可能需要 的大量抽象.与自制内核相比,您在其中处理桌面级硬件和标准库有助于开发.此外,自制内核最终希望成为自托管",即它们可以将 GCC 和 libstdc++ 移植到用户空间.同样,这是您在 Arduino 上下文中不会看到的.

Arduino is quite different from other embedded system projects. For one thing, it uses its own language based on C/C++. For another thing, you're dealing with incredible specialized software where it's unlikely that you'll need the heavy abstraction of <string> or <bitset>. Contrast with say a homebrew kernel, where you're dealing with desktop-grade hardware and the standard library aids development. Further, homebrew kernels eventually want to become "self-hosted", that is they can port GCC and libstdc++ to userspace. Again, this is something you're not going to see in an Arduino context.

现在,当您谈论 Arduino 附带的时,它是一个完全不同的故事.它们是用 C 或 C++ 编写的,可以从移植的标准库中受益,但这不太可能有帮助.移植 STL 并非易事,它非常非常大.大多数功能远不止是必要的——您真的需要 来读取或写入端口的字节吗?然后从开发人员的角度考虑成本和复杂性:Arduino 开发人员将承担这项艰巨的(并非有意的)任务来实现它,在大部分工作进行时支持它未使用或删除(想想自定义分配器.)

Now when you're talking about the libraries that come with Arduino, it's a completely different story. These are written in C or C++ and could benefit from a ported standard library, but it's unlikely to be helpful. Porting the STL is no easy task and it is very, very big. Most of the functionality is much more than necessary - do you really need a <string> or <bitset> to read or write bytes to a port? Then think about the cost and complexity from a developer point of view: the Arduino developers are going to take on this arduous (pun not intended) task to implement it, and support it when most of it is going to be unused or ripped out (think custom allocators.)

最后一点,市面上有大量不同规格的 Arduino 板.标准库是建立在现有 C 库之上的抽象.在某一时刻,您将不得不深入研究并实际编写 C 库和运行时的代码,这使得标准库本质上是不可移植的(想想 libstdc++-arm-none-eabi-newlib).

And one final point, there are a plethora of Arduino boards out there with different specs. The standard library is an abstraction built on top of an existing C library. At one point, you're going to have to get down and dirty and actually write the code for the C library and runtime, making the standard library inherently unportable (think libstdc++-arm-none-eabi-newlib).

现在,如果您对此不满意,您仍然可以按照他们的 教程 关于为 Arduino 编写自己的库.

Now if you're unhappy with this, you can still port a subset of the STL by following their tutorial on writing your own library for Arduino.

这篇关于Arduino 是否完全支持 C++ 标准库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆