Is the War Between C and C++ Over?

C & C++

Again after I was an engineering scholar and a budding younger engineer, it wasn’t uncommon to open (sure, bodily open) the most recent version of Embedded Methods journal and discover articles that had been contributing to the raging conflict between C and C++. Either side would current their circumstances as to why one language was higher than the opposite. The C builders normally argued that C++ produced bloated and inefficient code whereas the C++ builders would argue that C++ may do every little thing C may, solely higher. During the last a number of years, the rhetoric appears to have died away, leaving me to surprise “Is the conflict between C and C++ over?” and if that’s the case “Who received?”.

With a view to try to get a solution, I assumed the primary place to look could be to see if there was any change within the basic recognition between utilizing C and C++. Certainly, one of my favorite sources for such a comparability is the TIOBE Index. The TIOBE Index has been monitoring the recognition of programming languages normally since across the 12 months 2000, offering 20+ years of recognition information. For those who take a look at the TIOBE Index from February 2020, proven under, you’ll be able to see that aside from a small interval between 2003 and 2005, the recognition between C and C++ actually has modified that a lot. In actual fact, if something it seems like C++ has really misplaced momentum when in comparison with C!

This may appear to counsel that C has received, however how do issues look particularly inside the embedded programs business? If we return and take a look at the embedded business surveys and study the programming language utilization information for C and C++, we discover the next:

In all honesty, the above comparability to me typically seems fairly flat. Positive, you would say that the overall development since 2005 has been that C is trending up and C++ down, however the if I had been to calculate the usual deviation within the measurements that development is simply within the noise. We may additionally say within the final 5 years C++ has been trending up and C has been trending down, however once more the identical situation.

So how does C and C++ appear to check inside business? As I look out at basic tendencies because it pertains to utilizing C and C++, I really feel that there are a number of price noting. First, firms that promote microcontrollers and microprocessors typically are nonetheless offering their purchasers with software program stacks which can be written in C. I don’t see ST Microelectronics, Cypress, NXP, Renesas, Silicon Labs, and so forth offering C++ software program stacks to engineers, they supply all their code and examples in C. Second, after I begin to take a look at business and open supply software program packages for RTOS’s, bootloaders, file programs, and many others, the bulk all appear to be written in C. 

This fast look by business may lead me to imagine that C has received, however the reply sadly just isn’t that straightforward. For instance, take a look at common software program stacks reminiscent of Arduino and embed. These software program frameworks are utterly written in C++ and are gaining an increasing number of recognitions with time. In actual fact, I’m seeing a development the place embed is being leveraged an increasing number of by the chip producers and never simply by hobbyists or electrical engineers seeking to get one thing finished shortly.

Whereas the verbal and written conflict between C and C++ appears to have died down, C++ may really be beginning to achieve some floor in embedded programs. There are a number of explanation why I imagine that C++ is slowly rising in recognition which embody:

Continued enhancements within the C++ requirements

Continued enhancements in C++ compiler know-how

How simply C might be wrapped and used inside C++ functions

Entry to lessons, templates and different object-oriented constructs that aren’t included in C

Availability of helpful C++ sources reminiscent of:

Actual-Time C++ by Chris Kormanyos

Efficient Fashionable C++ by Scott Meyers

C++ has continued to evolve over the previous decade, particularly with main adjustments that occurred in C++ 11 and C++ 14. Whereas C has been improved, for essentially the most half the enhancements haven’t been supported nicely and most groups working with C nonetheless use C99 as their tried and true compiler. I feel lots of the outdated arguments for why C++ doesn’t work in embedded simply don’t apply anymore. These arguments typically revolved round how C++ bloated code, was inefficient and simply couldn’t entry {hardware} in addition to C. These simply aren’t true anymore and will not have even been legitimate again then.

When C++ is used, care definitely does have to be taken. Builders can’t use each customary library function, or they are going to doubtlessly get inefficient bloated code. In addition, they have to be cautious that any dynamic reminiscence allocations are finished throughout the start-up in order that they don’t run into reminiscence points like heap fragmentation. These are points that even C builders have to be cautious about, in order that they don’t preclude the usage of C++.

I don’t assume the conflict between C and C++ is over, however, I do assume that it has moved from a verbal and written battle to a battle of market share. On the finish of the day, C and C++ will proceed for use in embedded programs for many years to come back, locked in an everlasting battle for dominance. With the rising capabilities of compilers and microcontrollers, together with a cautious use of C++ options, there’s no motive that C++ needs to be instantly dominated out or excluded from being utilized in embedded improvement.

Leave a Reply

Your email address will not be published. Required fields are marked *