12

The "Arduino language" (as they call it) of the Arduino IDE 1 is obviously C++. Which C++ exactly?

I tried to figure it out myself (Arduino IDE 1.8.13 for Arduino Uno), but I can't conclude what C++ standard it supports.

From these tests, it seems to support C++14

  • C++ 14 variable templates are supported (template<typename T> constexpr T pi = T(3.1415926535);)

  • C++ 14 lambda captures are supported (auto lambda = [value = 1] {return value;};)

  • C++ 14 deprecated is supported ([[deprecated]]int fdep(){return 5;})

But not fully:

  • C++ 14 digit separators are not supported (int j = 2'000;)

From these tests, it even seems to support some C++17:

  • Nested namespace definitions are supported (namespace X::Y {int func(){ return 1; } })

But also not fully:

  • UTF-8 characters are not supported (char x = u8'a';)

If it partially supports everything, is there an overview like a list or table where I can look it up?

3
  • It supports whatever the particular core and compiler you are using supports and is configured to support. Turn on verbose compilation and you will see the commands it is running including the command line flags (-std*, etc).
    – Majenko
    Commented Oct 10, 2021 at 10:53
  • look around here arduino.github.io/arduino-cli/0.19/platform-specification/…
    – Juraj
    Commented Oct 10, 2021 at 12:42
  • I expect your tests to give different results on different versions of Arduino IDE and different boards. Commented Oct 11, 2021 at 9:18

1 Answer 1

15

The Arduino "language" is nothing more than a set of C++ functions and classes. It does not mandate any particular C++ standard.

The standard is dictated purely by the compiler that the core you are using happens to support (and is configured to use through command line flags).

Different cores use different compilers. Different versions of the same core use different compilers. Different compilers provide different C++ standard levels.

Most cores use GCC or some variant thereof. That could be anything from GCC 3.x.x through to the most recent release (whatever that is this week).

Currently the AVR core uses GCC 7.3.0 and is configured to use the gnu++11 standard by default (though avr-gcc and the associated libraries lack a full STL implementation). You can of course change that in the configuration files if you want.

6
  • "nothing more than a set of C++ functions and classes" -> And the very important preprocessing, which is missing for example in PlatformIO.
    – AndreKR
    Commented Oct 11, 2021 at 0:17
  • 1
    @AndreKR That's not really part of the language - more a bit of convenience fudging that really shouldn't exist anyway (and until fairly recently was broken horribly anyway).
    – Majenko
    Commented Oct 11, 2021 at 0:21
  • Without that preprocessing you would need something called "Header Guards", a technique so strange I find it hard to explain why it needs to exist.
    – AndreKR
    Commented Oct 11, 2021 at 0:51
  • 2
    @AndreKR No, that's wrong. All the preprocessing does is scrape your code for functions and insert prototypes for you at the top of your sketch. It does nothing with header guards, which is something you should always have in your header files regardless.
    – Majenko
    Commented Oct 11, 2021 at 0:58
  • 1
    @phuclv you're confusing the compiler and the STL which are two different things. True avr-gcc lacks the full STL but it is still C++11 (with GCC extensions) syntax.
    – Majenko
    Commented Oct 11, 2021 at 8:47

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.