Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a GCC pragma to switch C++11 on and off?

Tags:

c++

gcc

c++11

I have some headers that fight with C++11 but I'd like to use features like initializer lists in my code. My research says that you can enable newer features at the command-line only, like:

g++ -std=c++11

What I'd really like is to put in my code:

#pragma CXX11_OFF
#include <old.hpp>
#pragma CXX11_ON

vector<int> v {1,2,3};

I haven't been able to find such a pragma. Does it exist?

like image 901
Michael Fox Avatar asked Dec 14 '15 22:12

Michael Fox


People also ask

Does GCC support C++ 11?

According to cppreference, full support of c++11 came with gcc 4.8. 1; To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.

Does G ++ support C++ 11?

The g++ utility supports almost all mainstream C++ standards, including c++98 , c++03 , c++11 , c++14 , c++17 , and experimentally c++20 and c++23 . It also provides some GNU extensions to the standard to enable more useful features.

How do you specify STD C++ 11 in your Makefile?

You can use command-line flag -std to explicitly specify the C++ standard. For example, -std=c++98 , or -std=gnu++98 (C++98 with GNU extensions) -std=c++11 , or -std=gnu++11 (C++11 with GNU extensions)

What is pragma GCC optimize o3?

What Is "#pragma GCC optimize"? It turns on certain optimization flags for GCC. The syntax is #pragma GCC optimize (option, ...) From the official source on GCC pragmas, this pragma allows you to set global optimization flags (specified by option ) for functions that come after it.


3 Answers

#pragma GCC diagnostic warning "-std=c++11"

This line adds a cpp 11 flag to compiler.

like image 165
Łukasz Ptak Avatar answered Oct 17 '22 03:10

Łukasz Ptak


No. Such a pragma does not exist.

You can find a list of all pragmas GCC supports in § 6.61 of the manual.

like image 8
cantelope Avatar answered Oct 17 '22 05:10

cantelope


I don't know if there exists such a pragma. But turning C++11 on and off during the same compilation unit looks akward to me. Perhaps you should place the "old" part inside a dll and import it then in the "new" part. Then you can only compile the new part with c++11 enabled

like image 1
Liachtei Avatar answered Oct 17 '22 05:10

Liachtei