Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a reason not to use the newest C++ standard?

Tags:

I have seen that the default standard in IDEs is usually not the newest released standard, not even the newest standard in the IDE. For example JetBrains' Clion has C++20 and C++17 but the default option is C++14.

Is there a reason not to use the newest released standard?

like image 492
Elia Avatar asked Jun 21 '20 14:06

Elia


People also ask

Should I use the latest C++ version?

First, make sure the Configuration is set to “All Configurations”. From there, you can set the C++ Language Standard to the version of C++ you wish to use. We recommend choosing the latest standard “ISO C++ Latest (/std:c++latest)”, which as of the time of writing is the setting for C++20 support.

Should I use C89?

In conclusion, if you want portability for embedded or restricted systems, dynamic compilation, MSVC, or compatibility with proprietary source code, I would say C89 is advantageous.

What are the different C standards?

Let's continue with a discussion of all the five different standards of C — K&R C, ANSI C, C99, C11 and Embedded C. For the purposes of our discussion, the compiler used is the gcc C compiler from the GNU Compiler Collection (GCC).

Should I use C ++ 17?

I'd use the C++17 flag by default, it's the default in the latest version of clang too iirc. You should use the latest language features as long as you don't need to support builds on older compilers or embedded platforms that only have outdated compilers, as mentioned above.


1 Answers

As a general rule, use the latest standard if you can.

But, there are some reasons why you may in some situations choose to use an older one.

  • Your code makes use of features that changed behaviour in newer standards or were removed outright. If you don't have time to update your code, compiling for the older standard is reasonable.

  • Your tool-chain may not implement the new standard correctly. There could be known bugs that force you to stick to an older one.

  • You need to support multiple compilers on multiple platforms and not all combinations support the new standard yet.

  • You need to be binary compatible with code built by an older compiler for an older standard and you don't have the source to recompile it. In that case you may be forced to use the same old compiler and language standard to ensure ABI compatibility.

  • Internal company politics may mandate a specific version for arbitrary reasons.

  • Certification requirements may mandate use of a specific compiler and language version. Happens a lot in highly regulated industries, like medical.

  • Familiarity with the new features may be low on your team, so using them may increase the risk of bugs.

Etc (I've seen all of the above happen in real life btw)..

like image 112
Jesper Juhl Avatar answered Sep 20 '22 05:09

Jesper Juhl