
The main reason is that C++ automatically generates certain programs, such as constructors and destructors. Simple processors lack memory management and cannot accurately load a function into memory, which is also why C++ cannot be used in embedded systems and operating system boot processes. Additionally, C++ renames functions to support overloading.
The key factor is whether the compiler supports it, and whether your chip has enough RAM and flash memory. Infineon’s latest Tricore supports Rust, and common SoCs running Linux primarily use C++.
Microcontroller RAM and ROM are precious; the lower-level the language, the smaller the memory footprint and the higher the execution efficiency. Therefore, using C is better than using C++.

C language is characterized by its simplicity and efficiency, generating compact code with low memory and storage requirements, much like a frugal housekeeper who can make the most of limited resources to meet the high resource efficiency demands of microcontroller development.
C++, as an object-oriented programming language, has rich features and powerful capabilities, but these features often come with higher resource overhead. For example, object-oriented features in C++, such as virtual function tables, dynamic polymorphism, and template expansion, provide powerful programming capabilities but require additional memory space at runtime to support these features, which is difficult for resource-constrained microcontrollers to handle.
Moreover, some components in the C++ standard library, such as string, vector, and iostream, are feature-rich but have complex implementations that occupy significant memory space. Once used in a microcontroller, they can easily lead to insufficient memory, overwhelming the microcontroller’s RAM.
For instance, to implement an LED blinking function, using C language only requires a simple definition of the pin, toggling the level in a loop, and adding a delay, which can be easily achieved in just a few lines of code with minimal resource usage. However, if using C++, one might be tempted to define an LED class with various methods, even employing inheritance and polymorphism. While this makes the code appear more object-oriented and structured, it may cause the microcontroller to lag or even fail to operate normally due to insufficient resources.

The toolchain is deeply optimized for C language, allowing the compiler to efficiently convert C code into compact assembly code, resulting in high execution efficiency of the generated target code, much like a set of efficient production equipment tailored for C language, enabling C code to run very smoothly on microcontrollers.
However, C++ does not enjoy the same treatment in these toolchains. Due to the complexity and diversity of C++ features, optimizing C++ is more challenging, and the generated code is often less compact and efficient than that of C language.
Some may ask, what if I only use the basic features of C++ and avoid the complex ones? In reality, even when using only the basic features of C++, the advantages of C language in microcontroller development remain evident due to the more in-depth and mature optimization of the toolchain for C language. In the ecosystem of microcontroller development toolchains, C language is the favored “native resident,” while C++ is more like a “foreigner” trying to integrate but still somewhat out of place, leading to a disparity in ecological status that makes C language more user-friendly during development.
The object-oriented programming mindset of C++ emphasizes encapsulating data and operations into objects, completing tasks through interactions between objects. This programming approach has significant advantages in handling complex systems and large-scale code, improving code maintainability and scalability. However, in microcontroller development, where tasks are relatively simple, excessive abstraction and encapsulation can increase code complexity, obscuring the connection between code and hardware.
During debugging, stepping through complex operations such as virtual function calls in C++ can easily lead to confusion within the intricate code structure, making it difficult to quickly locate issues. The multiple layers of abstraction in C++ and its complex encapsulation make internal implementation details hard to observe and understand directly, which is not ideal for microcontroller development that seeks simplicity, directness, and efficient control.