A little C++ saves weeks of work
I went to see a potential client for my employer this week. The system is located in a large factory. We are looking at updating a factory automation system that controls a line of several machines, each as large as a townhouse. Everything about this equipment is big and potentially dangerous; parts weighing tons moving at high speed, tons of pressure and lots of molten steel on the move. The software must control hydraulic presses using tons of pressure with tolerances of thousandths of an inch. Sometimes embedded systems programming is really a lot more exciting than developing cool web sites.
One of the goals of the upgrade is to consolidate processes that run on several single board computers to a single processor. The original software was well structured but each subsystem that ran on a separate processor used the same names for equivalent variables, structure, functions, etc. Actually this is a good design technique since it brings out the concepts that are common across all of the processes making maintenance easier. But this common naming convention had become a major issue in their porting efforts due to namespace collisions. In addition there were some structures that were shared across the system and the new system would require only one copy of these common structures.
The easy answer to a problem like this would be to run each subsystem as a process under a general purpose OS like Linux. But this is the real world of embedded systems and some of the processes required sub-millisecond control loops. Under an RTOS they had chosen, all the software shares the same name space. Editing the source files by hand to rename all of the unique data, structures, and functions would be a tedious and error-prone task so I looked for another solution.
Though the software was written in C, I noticed that their new development system was using a full C++ compiler. This gave me the solution to their problem; C++ name spaces! I could place each of the subsystems into their own C++ namespace with a few lines of code in each file. Then I would have to create a namespace for the shared data. I still need to edit the files to explicitly reference the shared data but this is a much smaller task than renaming everything else. Meanwhile, all the remaining code stays in C which makes the customer happy.
Knowing C++ is a real asset even in when the client or the boss wants to reuse the existing C code. As my factory visit shows, sometimes a simple C++ feature can save weeks of effort in a software project.







