Where does C++ fit into your projects?

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Dear All

Can someone share their real time experience. I know here are so many experience person who have been worked on the real time project or still working on it.

I am very interested to know about your experience on embedded c++ Project.

Which micro-controller/processor / board you were using in your project ?

Which IDE you were using in your project ?

Thanks in advance
 

Papabravo

Joined Feb 24, 2006
21,159
AFAIK it has almost no place in embedded systems. The compiled code is simply too bloated for most microcontroller applications with limited RAM.
 
Last edited:

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Thanks for all of your for the advice. It would be better for me if you can share project object.

Have you worked on any project where you were using c++ programming for Embedded system ?

if controller support both C and C++ Why did c++ not c language ?

As far as i know, programming language depends on the hardware. if microcontroller supports c++ language then we can write c++ code

@Papabravo @KeithWalker @Ian Rogers
 

eduncan911

Joined Nov 14, 2011
29
I've used C a lot more than I'd prefer across microprocessors (using Arduino IDE) and RPi, etc. Even for some work as I had to interface with old OCR scanners that had APIs only in C. And while I know python (e.g. micropython) very well, I prefer not to use it on the grounds of speed and memory consumption (though it really is fast and lowish memory now).

C++, basically fixing old package builds on Linux, etc. Not really wrote anyrhing in it.

These days, one of two things happens: I pick microprocessors that only support TinyGo as I absolute love Golang (left 15 years in . NET, and years before that in Java for Golang).

https://github.com/tinygo-org/tinygo

Or,o I go the route of FPGAs. I'm now diving into the world of Real-Time processing and find the sequential flow of standard CPUs limited.

I've since picked up a few FPGAs and wow... These things are cool. Pure real-time concurrency by design, instead of trying to do cheap threading on a single or dual core CPU and trying to limit context switching on the heap. Once you have a solid solution, you can scale it up to more expensive FPGAs (given the same instruction set is the same).

If you are looking at real-time coding, take a hard look at FPGAs instead of C++. You'll still need an CPU and write code for processing the data IN and OUT. But the the design is something you can't beat for RT apps.
 

nsaspook

Joined Aug 27, 2009
13,079
Thanks for all of your for the advice. It would be better for me if you can share project object.

Have you worked on any project where you were using c++ programming for Embedded system ?

if controller support both C and C++ Why did c++ not c language ?

As far as i know, programming language depends on the hardware. if microcontroller supports c++ language then we can write c++ code

@Papabravo @KeithWalker @Ian Rogers
If the C++ design pattern was so superior for micro-controller development it would have been adopted wholesale years ago by hardware engineers. The types of problems C++ design patterns (relationships and interactions between classes or objects) are designed for do occur in small embedded projects but they are usually easily solved with simplistic, mainly static C code blocks while the types of problems C was designed for are very common in embedded systems, highly optimized and documented at the hardware low-level detail most HW engineers need.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,156
I've used C a lot more than I'd prefer across microprocessors (using Arduino IDE) and RPi, etc. Even for some work as I had to interface with old OCR scanners that had APIs only in C. And while I know python (e.g. micropython) very well, I prefer not to use it on the grounds of speed and memory consumption (though it really is fast and lowish memory now).

C++, basically fixing old package builds on Linux, etc. Not really wrote anyrhing in it.
Arduino code is C++ in actuality, so if you use the Arduino IDE to code, you are using C++!

Reference
 

402DF855

Joined Feb 9, 2013
271
As far as i know, programming language depends on the hardware. if microcontroller supports c++ language then we can write c++ code
Not true. C and C++ are general purpose languages and are equally suitable for most any processor out there.
f the C++ design pattern was so superior for micro-controller development it would have been adopted wholesale
Superior may (or may not) be an exaggeration. My guess as to why C++ has been somewhat slowly adopted in embedded systems has been that it isn't taught in engineering schools. And even when it is taught, I doubt there is much attention given to software design, which is a subject beyond just learning the language.
The compiled code is simply too bloated for most microcontroller applications with limited RAM.
This has been largely debunked as a myth. If one understands how C++ (or C for that matter) consumes too many resources, then one can modify the design to accommodate what is available.

Another issue I see is the evolution of C++ (or rather de-evolution). Most all of the language additions made since Stroustrup's original add complexity and obfuscation IMO without adding much benefit. Similarly, many C++ advocates seem to think STL, Boost, etc. are inherently part of the language - which they are not; those libraries are largely useless and bloated IMO and, I'd guess, originated and thrived in academia rather than "the real world".
 

eduncan911

Joined Nov 14, 2011
29
Not true. C and C++ are general purpose languages and are equally suitable for most any processor out there.
Superior may (or may not) be an exaggeration. My guess as to why C++ has been somewhat slowly adopted in embedded systems has been that it isn't taught in engineering schools. And even when it is taught, I doubt there is much attention given to software design, which is a subject beyond just learning the language.
This has been largely debunked as a myth. If one understands how C++ (or C for that matter) consumes too many resources, then one can modify the design to accommodate what is available.

Another issue I see is the evolution of C++ (or rather de-evolution). Most all of the language additions made since Stroustrup's original add complexity and obfuscation IMO without adding much benefit. Similarly, many C++ advocates seem to think STL, Boost, etc. are inherently part of the language - which they are not; those libraries are largely useless and bloated IMO and, I'd guess, originated and thrived in academia rather than "the real world".
402DF855' PGP ID's post is starting to remind me about this recent blog post from AAC:

Why Learn Assembly? For embedded systems

Which brings back old school modem days. :)

Arduino code is C++ in actuality, so if you use the Arduino IDE to code, you are using C++!

Reference
Lol. Which is so true!
 

Papabravo

Joined Feb 24, 2006
21,159
The original question was: "where does C++ fit into your projects". My answer from a career spanning half a century was: "it doesn't". That statement is essentially unassailable. If time and technology move on so that low end processors have 32 bit data busses and several gigabytes of memory then yeah, the ground has changed underneath our default assumptions and maybe it has a role. I'm retired now and I could care less.
 

djsfantasi

Joined Apr 11, 2010
9,156
The original question was: "where does C++ fit into your projects". My answer from a career spanning half a century was: "it doesn't". That statement is essentially unassailable.
On the other hand, I’ve yet to move to a platform unsupported by the Arduino IDE. The name may be misleading, but there are several other non-Arduino microprocessors supported by the IDE.

I’ve coded a runtime system on a Mega 2560. It has 18 (animatronic control) commands and can multitask (time slice) up to 127 processes. And it all fits comfortably in 256K with C++
 

nsaspook

Joined Aug 27, 2009
13,079
On the other hand, I’ve yet to move to a platform unsupported by the Arduino IDE. The name may be misleading, but there are several other non-Arduino microprocessors supported by the IDE.

I’ve coded a runtime system on a Mega 2560. It has 18 (animatronic control) commands and can multitask (time slice) up to 127 processes. And it all fits comfortably in 256K with C++
The Arduino language is C++, but it's a very restricted version of C++ (C with classes) that the IDE system transforms into C++ compatible code.
https://github.com/arduino/Arduino/wiki/Build-Process
 

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
Thanks for your advice

Here are the more experienced person's worked on many projects. I am a student and I never worked for any company

When you work for a company client give you project details and and you have to decide the hardware and programming language for the project.

It ever happened that you thought C language could not be used for this project and C++ is suitable for this project?

It would be helpful for me if someone share their project experience.

Have you done any project on embedded c++?

What was aim of your project. why did you use C ++?
 

ErnieM

Joined Apr 24, 2011
8,377
Programming languages are tools. An individual tool may have some advantage in some cases and disadvantage in others.

A hammer is a very poor tool when driving screws.

I have no reason to use assembly in any professional work, one exception. I used it once professionally when cheap compilers were not available and I had to upmanage my project to people who are best at blank stares.

I squeezed a LED controller into the smallest package I could as the LED and controller needed to fit into essentially the metal end of a pencil. (Actually the pencil is wider.) Written in C very tightly, with so little program memory I could not fit a single division into the program as the divide C used was larger than the entire code space. So I looped a subtraction to get it to fit.

When the processor allows it C++ is a better choice. I recently made a 4 channel RGBW LED controller (WiFi with Alexa). Each of the 4 hardware channels are abstracted as an instance of a C++ class. A bitch to write but once done it is brainlessly simple to make more instances.

C++ has a memory overhead usually requiring lots or RAM and a memory management system. C escapes some of this, and can use (albeit with efficiency losses) memory to simulate what is best done on a hardware stack. Of course assembly can wiggle thru lots of hoops if given the time to write that code. (Once upon a time I even wrote Windows COM objects in the MASM assembly package.)
 

Thread Starter

microcontroller60

Joined Oct 1, 2019
62
C++ has a memory overhead usually requiring lots or RAM and a memory management system. C escapes some of this, and can use (albeit with efficiency losses) memory to simulate what is best done on a hardware stack. Of course assembly can wiggle thru lots of hoops if given the time to write that code. (Once upon a time I even wrote Windows COM objects in the MASM assembly package.)
@ErnieM Thanks for long descriptions. no doubt C++ has more advantage as compared to C

I found that selection of C++ is depends on hardware capability and C++ can be use in GUI based Embedded project

I don't know I am right or wrong so I am explaining my understanding. Suppose we can make simple automatic pet feeder with C only but if we need GUI based automatic pet feeder then we can use C++ because Its object oriented programming language
 

402DF855

Joined Feb 9, 2013
271
C++ has a memory overhead usually requiring lots or RAM and a memory management system.
Cite specifics are stop spreading this myth. Sure, go crazy with inheritance and the virtual function tables take up space, use templates to duplicate tons of code for each scalar type (char, int, float, double etc) and memory will be used up. But applying OOD/OOP with a C++ implementation does NOT imply "lots" of RAM and memory management is really no different to C. New/delete and malloc/free are equivalent.
Suppose we can make simple automatic pet feeder with C only but if we need GUI based automatic pet feeder then we can use C++ because Its object oriented programming language
The embedded side and host based GUI are independent. Use C or C++ or assembly language on the embedded; for the GUI the sky is the limit. Use Java, C, C++, Python, or make up your own. The interface between the two will certainly be a serial protocol of some sort (UART, USB, ethernet, discrete IO) but each side can be implemented independently.

The advantage of C++ over C is that is it's a superset and therefore offers more options for the developer. If the developer is not well trained, the options may well be a disadvantage. OOD/OOP can make one more productive especially when re-using code from previous generations or products. But rarely will the selection of C++ versus C be a critical choice for the project. Either will do, as long as the developers are well trained.
 

KeithWalker

Joined Jul 10, 2017
3,063
Dear All

Can someone share their real time experience. I know here are so many experience person who have been worked on the real time project or still working on it.

I am very interested to know about your experience on embedded c++ Project.

Which micro-controller/processor / board you were using in your project ?

Which IDE you were using in your project ?

Thanks in advance
I worked for Hewlett Packard as a project engineer and a technical consultant in test and measurement for many years. I have designed automatic test systems for manufacturing customers' products to test everything from paper pulp to Nuclear fuel rods. I am also a keen hobbyist and have built very many electronic projects for my self. Over the years I have programmed in machine code without an assembler and with several different assemblers. I have programmed using punch cards and paper tape. I have used cobol, forth, fortran, basic, lisp, algol, CPL, PL/I, mumps C and C++ along with a hand full of specialized and high-level graphical languages. Each one I used was the best fit for the application at the time. On occasions, I used more than one language in the same program to optimize production and performance.
I recommend that you learn about all the current software languages that you can - where they excel and what limitations they have. With that knowledge, you will be able to pick which ever language is most suitable for your current application.
Regards, Keith
 

Ian Rogers

Joined Dec 12, 2012
1,136
Remember... C++ compiles to asm before its assembled to machine code as is C. Ergo C could be as efficient as both C++ and ASM.

C++ is good at management.. It doesn't use more memory it cost more in development (initially).. More code to write and such. When you write a class, no resources are used until it is implemented... It's the linkers job to include the code to be used..
 

nsaspook

Joined Aug 27, 2009
13,079
C endures because it's in the Goldilocks zone between ASM and OOP. I have zero love for OOP for the sake of OOP. The Linux kernel is very OO because of good design and it's written in C.
https://lwn.net/Articles/444910/
https://lwn.net/Articles/446317/

I think a major part of the C++ reluctance from HW types is that many software engineers (CS majors knowing C++) that work on hardware assume that hardware guys (EEs who know C) working on software want to abstract away the hardware details beyond what C delivers because it's boring, tedious and error prone unless there is great attention to detail. I've found the opposite to be true, that's what they love. If it need OO sugar that can be added without C++.
 
Last edited:
Top