Deaktivieren von C ++ 11 in GCC 7.3


11

Es scheint, als ob in Ubuntu 18.04 das standardmäßig gelieferte g ++ (Version 7.3.0) standardmäßig im C ++ 11-kompatiblen Modus ausgeführt wird. Ich erhalte einige Fehler in meinen alten Codes, die nicht C ++ 11-kompatibel sind. Ich habe g ++ - 6 (Version 6.4.0) installiert und die Programme werden gut kompiliert. Ist es möglich, den C ++ 11-Modus in g ++ - 7 zu deaktivieren?


2
Tatsächlich ist der Standardmodus von GCC 6 bereits C ++ 14 . GCC 7 bietet C ++ 17-Unterstützung. Es reicht wahrscheinlich aus, nur dieses C ++ 17-Zeug zu deaktivieren. Es ist nicht erforderlich, zu C ++ 11 zurückzukehren. Zurück zu C ++ 98 zu gehen ist wirklich ein gewaltiger Overkill (Underkill?)
MSalters

5
Was haben Sie in alten Programmen gemacht, die nicht kompatibel sind? Möglicherweise konnten Sie Dinge tun, die Sie aufgrund von Fehlern überhaupt nicht durften. In diesem Fall erhalten Sie nichts, wenn Sie zu c ++ 98 wechseln.
Am

9
@snb: Oder sie haben verwendet std::auto_ptr, oder sie haben autoin seiner ursprünglichen Gestalt verwendet, oder sie haben jetzt illegale Verengungskonvertierungen, oder sie haben verwendet export, oder, oder, oder
Leichtigkeitsrennen mit Monica


2
@LightnessRacesinOrbit Das meiste davon wäre vor C ++ 11 eine schlechte Übung gewesen.
Am

Antworten:


20

Versuchen Sie hinzuzufügen -std=gnu++98, es war wahrscheinlich die Standardeinstellung für gcc 6.4.0.

Beispiel:

g++ -std=gnu++98 hello.cpp -o hello

5
Wenn Sie ABI-Kompatibilität mit Code benötigen, der von alten GCCs kompiliert wurde, möchten Sie -D_GLIBCXX_USE_CXX11_ABI=0auch
Tavian Barnes

2
Oder -std=gnu++03für den letzten Standard vor C ++ 11. Erwähnenswert ist auch, dass -std=c++03einige GNU-Erweiterungen deaktiviert werden, die mit striktem ISO C ++ nicht kompatibel sind.
Peter Cordes

1
Im Godbolt-Compiler-Explorer ist C ++ 14 die Standardeinstellung für g ++ 6.3 godbolt.org/g/x2xPCS . C ++ 98 war die Standardeinstellung für g ++ 5.5 und älter. Ich habe den Wert überprüft __cplusplus: Wie wird die vom Compiler verwendete Version des C ++ - Standards ermittelt?
Peter Cordes

1

Von der man g++können Sie zwischen verschiedenen Dialekten wählen:

Options Controlling C Dialect
   The following options control the dialect of C (or languages derived
   from C, such as C++, Objective-C and Objective-C++) that the compiler
   accepts:

  -ansi
       In C mode, this is equivalent to -std=c90. In C++ mode, it is
       equivalent to -std=c++98.

       This turns off certain features of GCC that are incompatible with
       ISO C90 (when compiling C code), or of standard C++ (when compiling
       C++ code), such as the "asm" and "typeof" keywords, and predefined
       macros such as "unix" and "vax" that identify the type of system
       you are using.  It also enables the undesirable and rarely used ISO
       trigraph feature.  For the C compiler, it disables recognition of
       C++ style // comments as well as the "inline" keyword.

  -std=
       Determine the language standard.   This option is currently only
       supported when compiling C or C++.

       The compiler can accept several base standards, such as c90 or
       c++98, and GNU dialects of those standards, such as gnu90 or
       gnu++98.  When a base standard is specified, the compiler accepts
       all programs following that standard plus those using GNU
       extensions that do not contradict it.  For example, -std=c90 turns
       off certain features of GCC that are incompatible with ISO C90,
       such as the "asm" and "typeof" keywords, but not other GNU
       extensions that do not have a meaning in ISO C90, such as omitting
       the middle term of a "?:" expression. On the other hand, when a GNU
       dialect of a standard is specified, all features supported by the
       compiler are enabled, even when those features change the meaning
       of the base standard.  As a result, some strict-conforming programs
       may be rejected.  The particular standard is used by -Wpedantic to
       identify which features are GNU extensions given that version of
       the standard. For example -std=gnu90 -Wpedantic warns about C++
       style // comments, while -std=gnu99 -Wpedantic does not.

       A value for this option must be provided; possible values are

       c90
       c89
       iso9899:1990
           Support all ISO C90 programs (certain GNU extensions that
           conflict with ISO C90 are disabled). Same as -ansi for C code.

       iso9899:199409
           ISO C90 as modified in amendment 1.

       c99
       c9x
       iso9899:1999
       iso9899:199x
           ISO C99.  This standard is substantially completely supported,
           modulo bugs and floating-point issues (mainly but not entirely
           relating to optional C99 features from Annexes F and G).  See
           <http://gcc.gnu.org/c99status.html> for more information.  The
           names c9x and iso9899:199x are deprecated.

       c11
       c1x
       iso9899:2011
           ISO C11, the 2011 revision of the ISO C standard.  This
           standard is substantially completely supported, modulo bugs,
           floating-point issues (mainly but not entirely relating to
           optional C11 features from Annexes F and G) and the optional
           Annexes K (Bounds-checking interfaces) and L (Analyzability).
           The name c1x is deprecated.

       gnu90
       gnu89
           GNU dialect of ISO C90 (including some C99 features).

       gnu99
       gnu9x
           GNU dialect of ISO C99.  The name gnu9x is deprecated.

       gnu11
       gnu1x
           GNU dialect of ISO C11.  This is the default for C code.  The
           name gnu1x is deprecated.

       c++98
       c++03
           The 1998 ISO C++ standard plus the 2003 technical corrigendum
           and some additional defect reports. Same as -ansi for C++ code.
       gnu++98
       gnu++03
           GNU dialect of -std=c++98.

       c++11
       c++0x
           The 2011 ISO C++ standard plus amendments.  The name c++0x is
           deprecated.

       gnu++11
       gnu++0x
           GNU dialect of -std=c++11.  The name gnu++0x is deprecated.

       c++14
       c++1y
           The 2014 ISO C++ standard plus amendments.  The name c++1y is
           deprecated.

       gnu++14
       gnu++1y
           GNU dialect of -std=c++14.  This is the default for C++ code.
           The name gnu++1y is deprecated.

       c++1z
           The next revision of the ISO C++ standard, tentatively planned
           for 2017.  Support is highly experimental, and will almost
           certainly change in incompatible ways in future releases.

       gnu++1z
           GNU dialect of -std=c++1z.  Support is highly experimental, and
           will almost certainly change in incompatible ways in future
           releases.
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.