Image

Checking Out C++14

Aug. 25, 2014
Technology Editor Bill Wong takes C++14 for a test drive using Eclipse.

C++ has continued to garner more market share from C and the latest C++14 standard will help to continue this trend (see “C++14 Adds Embedded Features”). Most C/C++ developers are using compilers that support both but C still takes precedence for many for a variety of reasons. Support for legacy code is one reason. Corporate mandates are another. Unfortunately many stay away because of perceived complexity, inefficiency or that fact that it is an object oriented programming (OOP) language.

It is true that C++ is complex and it does support OOP. On the other hand, it is essentially a superset of C with OOP to complement the procedural features (see “Bjarne Stroustrup Talks About C++14”). The latest version adds a number of simple but very useful features like user defined literals. It also has the auto keyword that lets the compiler figure out the type of a value which is already knows. Even embedded C programmers will appreciate the binary literals and digit separator. This allows statement like:

auto a1 = 0b1011111101011011;
auto a2 = 0b1011'1111'0101'1011;

I decided to get some hands on use of C++14. Most of this support has been in a lot of compilers for a while now. Unfortunately, some of the embedded development systems I have been working with didn’t have the latest so I had to download the latest version of Eclipse, code name Kepler, and the GNU C compiler. I tried it out on Fedora 20 since I had that installed on one of my lab machines.

The Eclipse and GNU tool installation was a simple yum install since the tools are in the Fedora repository. The C++14 support is still new so I had to enable it via command line options for the compiler. It is just matter of adding -std=c++14 in the right spot. That happens to be under the GCC Built In Compiler Settings. After that, my sample C++14 apps worked rather nicely.

I had a chance to play with the user defined literals. I don’t think templates work very well for the definition side but templates are useful for handling data type operations. I have just being working with the basics like weight and distance. Time is already handled by the new STL (standard template library) support.

I also had a chance to work with the C++11 features. I really had not given them a thorough workout and the C++11 change list was even more extensive. Features like generic lambda expressions got added to the mix. These are nameless functions although they are more like closures because you can capture local values as variables that are global with respect to the function. Lambdas were also a recent addition to Java (see “Lambda: Reclaiming An Old Concept”).

If you use C++ then enjoy checking out the latest C++11 and C++14 features. They are worth the effort and make programming easier and clearer. If you are still stuck with C then check out C++. It is definitely better and it can actually be more efficient and safer in the long run. You just need to know what the compiler is doing and that is true for any programming language.

About the Author

William Wong Blog | Senior Content Director

Bill Wong covers Digital, Embedded, Systems and Software topics at Electronic Design. He writes a number of columns, including Lab Bench and alt.embedded, plus Bill's Workbench hands-on column. Bill is a Georgia Tech alumni with a B.S in Electrical Engineering and a master's degree in computer science for Rutgers, The State University of New Jersey.

He has written a dozen books and was the first Director of PC Labs at PC Magazine. He has worked in the computer and publication industry for almost 40 years and has been with Electronic Design since 2000. He helps run the Mercer Science and Engineering Fair in Mercer County, NJ.

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!