Leveraging C++

Thread Starter

Futurist

Joined Apr 8, 2025
925
I've recently started exploring C++ and might start using that language for my STM32 projects. I decided to look at which language features are more relevant and which are less. So I did some digging and found that just a few features would in-effect give me a more powerful C without any of the baggage that comes with the OO stuff.

I began with references and this is very helpful, lets us avoid the pitfalls of pointers at no cost, a genuine language capability.

But I'm also going to understand typed fixed length arrays, consteval (e.g. lookup tables) and a few more.

These come under the "zero cost abstractions" heading I believe.
 

dashstofsk

Joined Jun 16, 2013
7
The original C++ compilers were written in C. It follows that everything you can do with C++ can be done with C. However it would take you many more lines of code. OO programming was the basis on which higher performance software could be written. It was created to make software jobs easier.

If you were to explore C++ in more depth I think you will come to the conclusion that OO doesn't come with baggage. Pointers are not new to C++. They are and always have been a powerful feature of C.
 

Thread Starter

Futurist

Joined Apr 8, 2025
925
I’d be interested to know how you get on. What sort of things do your STM32 projects do?
My main objective would be to define a subset of C++ that avoids OO as much as it can and gives us effectively an improved C.

C is weak and error prone and it strikes me as sensible to use C++ to overcome some of the weaker areas without embracing too much C++.

I may not bother though, I've kept C++ at arms length for decades and learning a new language well is an effort.

I use OO all the time with C# and it's done well in that language, but some OO features in C++ are old ideas now (like inheritance) and avoiding that kind of things is what I'd like to do.

I don't do much, I enjoy just getting the peripherals going and designing useful libraries, I'm not a professional MCU developer.
 
Top