I was trying to make use of precompiled headers to speed up compilation following this link: https://codeforces.com/blog/entry/53909
I observed that pre-compilation of headers and subsequent compilation of .cpp programs have to be done using the same g++ flags for the speed-up to work, which makes sense. However, explicitly setting the c++ standard to the default one did not work. So, neither of pre-compilation using g++ stdc++.h
and subsequent g++ -std=c++14 program.cpp
, nor, g++ -std=c++14
and g++ program.cpp
worked.
This didn't make sense to me as I knew that my compiler, x86_64-w64-mingw32-g++.exe (gcc version 10.2.0), by default, conforms to 201402L (c++14) standard, which I figured using g++ -dM -E -x c++ /dev/null | fgrep __cplusplus
, and getting the following response:
#define __cplusplus 201402L
So, my question is, what is the difference between g++ and g++ -std=c++14 when g++, by default, adheres to 201402L? Also, is it significant enough for me to specifically opt for either one of them ?
GCC doesn't compile with
-std=c++14
by default. The description of the-std
flag from the GCC man pages (for version 9.3.0) saysEmphasis mine. The current default is
-std=gnu++14
, which targets the C++14 standard while also enabling GNU extensions to the C++ language. The distinction between the-std=c++XX
flags and the-std=gnu++XX
flags is explained further in What are the differences between -std=c++11 and -std=gnu++11?.