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>?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
NonCreature0714
  • 5,744
  • 10
  • 30
  • 52
  • 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 01 '16 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. – uh oh somebody needs a pupper Jun 01 '16 at 18:10
  • "Standard-Library is probably the most efficient", well, actually, it's not. – David Haim Jun 01 '16 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 01 '16 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): https://github.com/maniacbug/StandardCplusplus – Violet Giraffe Jan 24 '18 at 23:04

1 Answers1

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.

Will
  • 1,124
  • 12
  • 33
  • Great answer, that's what I was looking for, thanks! – NonCreature0714 Jun 01 '16 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: http://www.atmel.com/webdoc/avrlibcreferencemanual/FAQ_1faq_cplusplus.html – statueuphemism Jul 12 '17 at 16:55
  • 19
    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. – jose.angel.jimenez Jan 18 '19 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 09 '19 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 '20 at 21:43
  • Nice answer but so.... to be clear we are on our own if we want to use std::bitset on arduino... Not reinventing the wheel is NOT ridiculous. – JB. Nov 27 '20 at 12:59