C++ What determines which version of C++ can run on a specific architecture (like Arduino)

406 views Asked by At

I know there are slight changes to C++ like C++11 or C++14. If I have a microcontroller or other computer device, what is it that determines if the code can be run on that computer. I.e. what determines if the Arduino can run C++14 code or not?

Is it the compiler on my machine, the interpreter on the other system's processor or what?

3

There are 3 answers

2
Kiril Kirov On BEST ANSWER

It's the compiler's version. If the compiler supports the syntax/C++ version and if the compiler is suitable for the platform - then a valid code will be produced.

0
Tim Seguine On

Any computer platform can in principle support any arbitrary programming language as long as someone has written a compiler for it.

The processor itself is agnostic to which programming language is used, but even if it weren't that wouldn't necessarily rule out support for other languages or dialects in the compiler via source code translation.

Whether you get new C++ standards support on your Arduino is completely at the whim of the people who are providing the compiler toolchain and standard library you are using.

0
dureuill On

@Kiril Kirov's answer is correct, it depends mostly on compiler availability, but some other elements are at stake.

The compiler is responsible for transforming C++ code to machine code in the native instruction set. It also relies on the c++ standard library which obviously needs to be compilable for your system using said compiler. Note that after this operation the produced code is not essentially different from other native code produced by other means (using a C compiler or written by hand), so there's no reason it wouldn't be executed by your microprocessor.

You also need a linker which knows the memory layout of the target microcontroller (processor+RAM+flash memory or ROM).

You also need a way to flash the code to your system, such as USB link and drivers.

In arduino's case, you can find all these elements readily available because it is a known platform (Arduino runs on AVR or ARM depending on the version, so possible compilers would be respectively avr-gcc or arm-none-eabi-gcc), but in more exotic cases it isn't a given (chances are that you cannot flash your Mastercard).