C++ is a very decent programming language that has a very strong compiler supported by a big community on a range of different platforms. The C++ language definitions, syntax, and functionality are organized into different standards. Those standards are usually named after the year the standard was adopted such as 1998 for C++98, 2011 for4 C++11, 2014 for C++14, and 2017 for C++17. One of the great features of a C++ compiler is you can choose which standards you want your code to be compiled against, before the compilation of your source code. This allows the compiler to check that your code complies with that standard. In this post, we explain what the standards are, how you can view them, how you can check the compatibility of your C++ source code against different standards, and how you can choose to use C++ standards in C++ compiler options.
Table of Contents
What is a C++ standard?
Standards are an international agreement for C++ compilers, made by the IDE and compiler developers of different operating systems (Embarcadero C++ Builder, Microsoft MSVC, GNU GCC, Apple Swift, etc.). They are formal, legal, and very high-level detailed technical documents intended primarily for people writing C++ compilers and standard library implementations.
The current available standards and some of their key features are listed below.
How to use C++ standards in C++ compiler options?
When we use '-std='
option in a C++ compiler this option type enables or disables some features. We need to use these features to see the effect of each C++ standard option.
Personally, I always prefer to use the latest version of the standards in my compilers. However, when programming, sometimes you may have to work on old or legacy C++ source, or you may be programming to another company that uses older standard compilers. Or maybe you just want to check if your code is compatible with a particular standard, or the code uses new standards. At these times, you can use std option in C++ compilers.
In general, we can use the -std
option to compile to a particular C++ standard. Here are some option examples,
-std=c++98
-std=c++11
-std=c++14
-std=c++17
-std=c++20
or-std=c++2a
For example, if you want to compile your code with C++11 features, you can use C++ Builder 64bits command line compiler as shown below:
1 |
bcc64 -std=c++11 myapp.cpp -o myapp |
For an example, we can write this C++ code below which uses a feature found in the C++17 standard and above.
1 2 3 4 5 6 |
int main() { static_assert(sizeof(int)==4); // C++17 feature return 0; } |
If you are using the C++17 compiler, this code will be compiled successfully because the static_assert
feature comes with C++17. If you compile this code with -std=c++11
or -std=c++14
options this time you will get warning which is telling you that you have requested C++ standard version 11
, but there is a feature that requires C++ standard version 17
(Until C++17
, a message was required w/ static_assert
).
How to use C++ standards in the C++ Builder compiler options?
In C++ Builder CLANG compiler, we can use -std
option to compile in previous standards. This option can be used in bcc32c and bcc64, both support these std options below,
-std=c++11
-std=c++14
-std=c++17
I should note that, C++11 and C++14 options are partially supported, these options do not have a STL
that works with all, so you have the latest STL one for C++17
. According to the bcc32c and bcc64 compilers, these all std options below are supported ‘partially’.
- -std=c++98 or -std=c++03 for ‘ISO C++ 1998 with amendments’ standard
- -std=gnu++98 or -std=gnu++03 for ‘ISO C++ 1998 with amendments and GNU extensions’ standard
- -std=c++11 for ‘ISO C++ 2011 with amendments’ standard
- -std=gnu++11 for ‘ISO C++ 2011 with amendments and GNU extensions’ standard
- -std=c++14 for ‘ISO C++ 2014 with amendments’ standard
- -std=gnu++14 for ‘ISO C++ 2014 with amendments and GNU extensions’ standard
- -std=c++17 for ‘ISO C++ 2017 with amendments’ standard
- -std=gnu++17 for ‘ISO C++ 2017 with amendments and GNU extensions’ standard
For example, if you want to compile your codes with C++11 features and below, you can use C++ Builder CLANG compiler as below,
1 |
bcc32c -std=c++11 myapp.cpp -o myapp |
or you can use 64bits C++ Builder compiler as below,
1 |
bcc64 -std=c++14 myapp.cpp -o myapp |
Here are all of my tests with some simple C++ code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
D:\#PROJECTS\testq>bcc32c -std=c++98 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=gnu++98 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=c++11 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=gnu++11 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=c++14 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=gnu++14 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=gnu++14 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=c++17 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. D:\#PROJECTS\testq>bcc32c -std=gnu++17 myapp.cpp Embarcadero C++ 7.60 for Win32 Copyright (c) 2012-2023 Embarcadero Technologies, Inc. myapp.cpp: Turbo Incremental Link 6.98 Copyright (c) 1997-2023 Embarcadero Technologies, Inc. |
How to use C++ standards in GNU C++ compiler options?
In GNU gcc / g++ compiler, we can use the -std
option to compile to various C++ standards.
-std=c++
98-std=c++11
-std=c++14
-std=c++17
-std=c++
20 or-std=c++
2a
For example, if you have C++17 compiler, you can compile the myapp.cpp
file using the C++11 standards as shown below:
1 |
g++ -std=c++11 myapp.cpp -o myapp |
How to use C++ standards in MSVC compiler options?
According to Microsoft , these are the standard options that can be used as below. More information can be found here document here.
/std:c++14
/std:c++17
/std:c++20
/std:c++latest
/std:c11
/std:c17
How to use C++ standards in CLANG compiler options?
In CLANG clang++ compiler, we can use the -std
option to compile to specific C++ standards as shown below.
-std=c++98
-std=c++11
-std=c++14
-std=c++17
-std=c++20
For example, if you have C++17 compiler, you can compile myapp.cpp
file using the rules of the C++14 standard as shown below.
1 |
clang++ -std=c++14 myapp.cpp -o myapp |
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition