Checking Out C++14

Checking Out C++14

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.

TAGS: Dev Tools
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.