21

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

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.

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?

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

5
  • 2
    This does not seem to be a duplicate at all. It does not mention the Arduino string library at all and has a completely different context and scope.
    – Vality
    Jun 1, 2016 at 17:44
  • "Arduino" is kind of broad. That's like asking if the standard library is available on a microcontroller. You need to find out if a SDK is available or if somebody has ported the standard library for your specific platform. Jun 1, 2016 at 18:10
  • "Standard-Library is probably the most efficient", well, actually, it's not.
    – David Haim
    Jun 1, 2016 at 18:13
  • 2
    @NonCreature0714 FYI: Check out my BitBool lib in the library manager, it manages a bitset like an array.
    – Chris A
    Jun 1, 2016 at 22:43
  • Arduino Due toolset has the standard library, while Arduino Uno is lacking it. But someone fixed that (and this is only one of several such projects on Github): github.com/maniacbug/StandardCplusplus Jan 24, 2018 at 23:04

1 Answer 1

9

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.

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.)

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).

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.

6
  • Great answer, that's what I was looking for, thanks! Jun 1, 2016 at 19:01
  • As an added comment, even the microcontroller manufacturers often do not supply the C++ standard library implementation. If they did, it would be easy to incorporate into the Arduino development environment. For example: Atmel microcontrollers are used in a lot of the Arduino boards and here's a post from Atmel on the lack of support for various C++ features, including the standard library using Atmel's development infrastructure: atmel.com/webdoc/avrlibcreferencemanual/FAQ_1faq_cplusplus.html Jul 12, 2017 at 16:55
  • 22
    Not at all, Arduino does NOT use its own language. Arduino uses standard C++ and a standard industrial grade C++ compiler (gcc). It is not black magic nor has any substantial difference to any other embedded project. The main and biggest difference is they have really managed to lower the entry barrier to developing simple embedded applications. Jan 18, 2019 at 20:38
  • 7
    Totally wrong. It doesn't use its own language at all. It uses hex files compiled from, generally, c++ and the gnu and Arduino toolchain.
    – RichieHH
    Mar 9, 2019 at 13:20
  • In @Mark Amery's defense: Arduino documentation tells such fake narrative. They are talking about Ardunio as language... God knows why and how they got there.
    – hardyVeles
    Feb 19, 2020 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.