Which C++ standard is the default when compiling with g++?

后端 未结 9 573
故里飘歌
故里飘歌 2020-11-29 23:59

I have a piece of code that looks like the following. Let\'s say it\'s in a file named example.cpp

#include 
#include 

        
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 00:19

    You can also check with gdb

    1. $ g++ example.cpp -g Compile program with -g flag to generate debug info
    2. $ gdb a.out Debug program with gdb
    3. (gdb) b main Put a breakpoint at main
    4. (gdb) run Run program (will pause at breakpoint)
    5. (gdb) info source

    Prints out something like:

    Current source file is example.cpp
    Compilation directory is /home/xxx/cpp
    Located in /home/xxx/cpp/example.cpp
    Contains 7 lines.
    Source language is c++.
    Producer is GNU C++14 6.3.0 20170516 -mtune=generic -march=x86-64 -g.
    Compiled with DWARF 2 debugging format.
    Does not include preprocessor macro info.
    

    There is the standard used by compiler: Producer is GNU C++14

    If you recompile your program using -std=c++11 (for example), gdb detects it: Producer is GNU C++11

提交回复
热议问题