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

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

问题描述

不是询问<string>,而是询问用于微控制器的整个标准库.

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

我还没有一块Arduino板来执行代码,正如标题所述,我很好奇Arduino是否已完全支持C ++ Standard-Library,并且已经成为Arduino IDE的一部分.毋庸置疑,Standard-Library可能是最高效,经过充分测试并且资源最少的可公开获得的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?

如果Standard-library不是Arduino IDE的一部分,那么如何包含<algorithm><bitset>之类的特定库?

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 ++的自己的语言.另一方面,您正在使用令人难以置信的专用软件,在该软件中,不太可能需要大量的<string><bitset>抽象.与自制"内核形成鲜明对比,自制"内核用于处理桌面级硬件,而标准库则有助于开发.此外,自制内核最终希望成为自托管"内核,也就是说,它们可以将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并非易事,而且非常大.大多数功能超出了必要的范围-您是否真的需要<string><bitset>来将字节读取或写入端口?然后从开发人员的角度考虑成本和复杂性: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).

现在,如果您对此不满意,仍然可以通过遵循STL的教程有关为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天全站免登陆