5

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?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Startec
  • 12,496
  • 23
  • 93
  • 160
  • 5
    I sure hope C++ is not _interpreted_ on Arduino. All you need is a C++11/C++14 compiler that targets your platform. Also, I wouldn't call the changes introduced by C++11 "slight changes" by any means. – dureuill Jun 10 '15 at 07:02
  • @dureuill I see and by platform that would be whatever chip is on the Arduino? (like ARM 32 or something)? – Startec Jun 10 '15 at 07:03
  • 2
    Arduino is not a architecture. Arduiono runs on AVR, ARM, ... It simply is a collection of functions/classes which helps to fast develop access to uC hardware and deliver some additional helper stuff. The compiler must generate specific code for the underlying device and the cpu specific libs must be selected from the environment for compile ( Makefile, IDE, ... ) – Klaus Jun 10 '15 at 07:04
  • 1
    @Startec Here's a link to an answer that explains how to compile c++11 to arduino: http://stackoverflow.com/a/18527499/1614219 – dureuill Jun 10 '15 at 07:08

3 Answers3

7

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.

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
  • So if the compiler is able to compile code for the platform (meaning, in this case the Arduino) and the compiler can understand the version of C++ then runnable code will be produced? – Startec Jun 10 '15 at 07:02
  • 2
    @Startec - yes, exactly. – Kiril Kirov Jun 10 '15 at 07:03
5

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

dureuill
  • 2,526
  • 17
  • 24
0

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.

Tim Seguine
  • 2,887
  • 25
  • 38