Loading lessons...
Language Standards and Compiler Settings
Language Standards and Compiler Settings
C++ doesn't stay still. Every few years a brand new standard arrives, like a fresh version of the language.
A tour of recent standards
- C++11 (2011), C++14 (2014), C++17 (2017), C++20 (2020), and C++23.
Each new release adds features, improves the library, and sometimes makes old code faster by default.
Choosing a language standard
A compiler can often "speak" several standards. You pick which one with a setting:
- g++:
-std=c++20 - Clang:
-std=c++17 - In an IDE: project settings -> C++ language standard dropdown.
A good default these days is C++17 or C++20. Make sure the chosen standard exists in your compiler.
Compiler extensions
Compilers also add extra, non-standard features ("extensions") to tempt you. They're fine locally, but code that depends on them may not compile on other compilers. Keep everything portable.
Build configurations: Debug vs. Release
- Debug - built to be easy to debug: slower, includes extra checks, no release-level optimization.
- Release - highly optimized, fast, and small. This is what the users run.
You usually develop in Debug, then switch to Release for shipping.
Warning levels
Compilers warn about suspicious code (even when it's not an error). Turn the warning level up so you catch problems early and cheaply.
TL;DR
- Standards: C++11 -> C++14 -> C++17 -> C++20 -> C++23.
- You can set the standard, e.g.
-std=c++20, or in IDE options. - Debug config is for developing; Release is for fast, optimized apps.
- Use warnings; try to avoid compiler-specific extensions.