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?
1 Answer 1
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.
-
"nothing more than a set of C++ functions and classes" -> And the very important preprocessing, which is missing for example in PlatformIO.AndreKR– AndreKR2021年10月11日 00:17:57 +00:00Commented 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– Majenko2021年10月11日 00:21:58 +00:00Commented 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– AndreKR2021年10月11日 00:51:52 +00:00Commented 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– Majenko2021年10月11日 00:58:36 +00:00Commented 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– Majenko2021年10月11日 08:47:12 +00:00Commented Oct 11, 2021 at 8:47
-std*
, etc).