0

I started using an Arduino Uno days ago. I'm an experienced C++ dev and I'm kind of confused.

Is the Arduino compiler different than a C++ one? What C++ version does Aruidno Uno use? Why it doesn't it support STL? Is it possible to use STL?

Also, can I configure their cpp file and use my own main function? The loop / setup thing really does annoy me. Thanks!

2
  • turn on verbose output in preferences ... examine the resulting info in the console window
    – jsotola
    Commented Jan 1, 2022 at 19:03
  • is that an arduino ide things? bcs im using platform io
    – ZakiMkn
    Commented Jan 1, 2022 at 20:06

1 Answer 1

2

Yes, there are STL implementations for the Arduino Uno (check the library manager). Note that some of them are unsupported and/or outdated quite a bit. The downside of using STL on the Arduino is also that these classes may use to much memory. Because of it's very limited memory (only 2kb), dynamic memory allocation is quite risky, as memory fragmentation will quickly cause the program to crash.

The Arduino build system uses a pre-build step around the ino files that remove a lot of pain locating header files and setting up build paths from the user. This is a bit confusing at first for an experienced C++ programmer, but it simplifies things a lot, particularly when it comes to using different libraries. This build step automatically locates the include paths for all .h files referenced in the .ino. The system requires that you declare the loop() and setup() methods, but what you do with them is up to you. You can leave either of them empty, or never return from the loop function, calling into whatever main function you want to use.

As a side note: There are other C++ compiler features that are disabled or unsupported on the Uno because they would make the code to big. These include dynamic type casting using dynamic_cast<> and exception handling.

2
  • Thanks! i googled the disabled compiler features and i didnt found them, can u tell me more about them or their is only dynamic casting and exeptions?
    – ZakiMkn
    Commented Jan 1, 2022 at 20:05
  • I have found about these only, but there might be more. The compiler is actually a normal GCC (although a bit an old version) and so supports the full set of C++11 features, but the runtime library is missing some pieces.
    – PMF
    Commented Jan 2, 2022 at 7:38

Your Answer

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

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