V
V
vmklukva2016-12-02 13:57:40
C++ / C#
vmklukva, 2016-12-02 13:57:40

C or C++ for microcontrollers. Why C?

Good afternoon!
Let's say I'm starting to program ARM microcontrollers (STM32, Milandr). I have been using the C++ language, the EmBitz and CodeMaster-ARM environments for a year now. There are no problems. But recently I noticed that most of the code (in fact, I never met files with the *.cpp extension at all) for these stones is written in C. Accordingly, I asked myself the question - why? On the Internet I found only that the weight is less. Are there any other advantages that C has over C++?
PS The question is purely out of curiosity.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
O
OnYourLips, 2016-12-02
@vmklukva

1. C is a cross-platform assembler. Such tasks are his mission. This is how it happened historically.
2. The size of the runtime and the resources used are very different, overhead when using objects. On an MCU with 8kb of memory, this is critical.
3. Huge difference in the complexity of languages. Often MK is done by people who are closer to hardware than to software development.

S
sitev_ru, 2016-12-02
@sitev_ru

On the Internet I found only that the weight is less.

this is the answer)

C
CityCat4, 2016-12-02
@CityCat4

1. compile for any hello world controller in C and plus. Then look at the size of the resulting binary. For the controller, the size of the binary is not just important, but crucial.
2. The final (assembler) code is simpler, runs faster, there is less overhead on abstraction - programs for controllers are very often written by half-programmers, half-hardware, who think in terms of hardware and do not need an abstraction level of pluses

V
Vasily Melnikov, 2016-12-02
@BacCM

That's how it happened historically. Almost everything I've dealt with has tolerable compilers for C and a bunch of bugs for C++.
It turns out in C ++ in this environment not a very large request, and therefore it is not really optimized, clumsily. As a result, developers prefer C.
In the last big project under OMAP, I chose C ++ because. seems to be well supported by TI's CCS. But at first I heard a lot of unflattering things on this subject from the team. While they figured out how to get around all the rakes, they killed a lot of time.

L
Lmx2315, 2016-12-11
​​@Lmx2315

It is possible that the firmware in C++ will be slower, again due to the amount of code and a larger number of memory operations. Since local variables will be mainly used, and they are stored by the compiler on the stack, which will have to be overwritten back and forth a bunch of times, which takes time.

S
Sh0ttky, 2016-12-22
@Sh0ttky

In my opinion, si is generally better in principle. It just becomes more noticeable on microcontrollers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question