Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the C++ Standard Library fully supported on Arduino?

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

like image 737
NonCreature0714 Avatar asked Jun 01 '16 17:06

NonCreature0714


People also ask

Does Arduino support C?

All standard C and C++ constructs supported by avr-g++ should work in Arduino. For more details, see the page on the Arduino build process.

Can you use std in Arduino?

The good news is: yes that's possible! Even if some feature will still be lacking, or some others will be limited, you will be able to use things like std::vector and std::string in your Arduino programs.

What version of C does Arduino use?

The Arduino Language? - The "Arduino Language" is C++. There is a bit of preprocessing to save you doing function prototypes, but it most definitely is C++.

Does Arduino support C++11?

C++03 is obsolete, Arduino uses C++11, which is a huge improvement over 03. As others have mentioned, the GCC avr-g++ compiler that comes with the Arduino IDE fully supports the C++ language, with the exception of the standard library.


1 Answers

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.

like image 127
uh oh somebody needs a pupper Avatar answered Sep 29 '22 13:09

uh oh somebody needs a pupper