Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c++11

g++

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?

like image 481
Startec Avatar asked Jun 10 '15 06:06

Startec


2 Answers

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.

like image 150
Kiril Kirov Avatar answered Oct 23 '22 03:10

Kiril Kirov


@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).

like image 24
dureuill Avatar answered Oct 23 '22 04:10

dureuill