g++

Performance difference between gcc and g++ for C program

十年热恋 提交于 2019-12-19 17:42:45
问题 Lets say i have written a program in C and compiled it with both gcc and g++, which compilation will run faster? gcc or g++? I think g++ compilation will make it slow, but not sure about it. Let me clarify my question again because of confutation about gcc. Let say i compile program a.c like this on console. gcc a.c g++ a.c which a.out will run faster? 回答1: http://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/G_002b_002b-and-GCC.html GCC is a compiler collection. It is mainly used for compilation of C

Return type deduction with multi-statement lambdas

我们两清 提交于 2019-12-19 16:53:09
问题 I've been writing code, and I've recently found out that g++ doesn't warn me about a certain class of issue: per C++11 5.1.2.4, if your lambda is not a single return statement then the return type must be declared as a trailing-return-type or be void. Although g++ is allowed to compile invalid code if it makes enough sense, is there a way to either turn this behavior off (allowed with -fpedantic in g++-4.7) or all least warn about it? Example code: []() { return 0; } //is fine [&a]() { a++;

Array allocation in C++ on stack with varying length [duplicate]

北城余情 提交于 2019-12-19 10:25:03
问题 This question already has answers here : C++: Why does int array[size] work? (3 answers) Closed 6 years ago . I was surprised to find out that it is possible to allocate an varying-length array on the stack in C++ (such as int array[i]; ). It seems to work fine on both clang and gcc (on OS/X) but MSVC 2012 don't allow it. What is this language feature called? And is it an official C++ language feature? If yes, which version of C++? Full example: #include <iostream> using namespace std; int

Is this a legitimate C++ code? [closed]

 ̄綄美尐妖づ 提交于 2019-12-19 10:14:57
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago . The code comes from here Given that in C++ you can use C libraries would you say that the following code is a legitimate C++ code? If not what changes need to be applied? This code compiles with g++ and runs as

g++ O1 is not equal to O0 with all related optimization flags

£可爱£侵袭症+ 提交于 2019-12-19 09:51:11
问题 I know the title is a bit confusing. Let me clarify my problem with a little background: My program behaves strangely when I compile it with -O1 flag vs -O0 flag in terms of execution time. I know -O1 flag does many optimizations such as fauto-inc-dec -fbranch-count-reg -fcombine-stack-adjustments (More than 40 according to the man page). To figure out which optimization(s) cause this behavior, I plan to remove flags one at a time then compile and test to see if something changes. Before

Template argument deduction for class templates in C++17: am I doing it wrong?

非 Y 不嫁゛ 提交于 2019-12-19 09:14:20
问题 According to https://gcc.gnu.org/projects/cxx-status.html, version 7 of g++, used with flag -std=c++1z , supports template argument deduction for class templates. I would expect the following code to compile, especially as Base is an abstract class, therefore: 1. the compiler knows no instance of Base can be created; 2. the pointer to base pt_base points to a clearly defined instance (i.e. Derived<int>{42} ) where the type ( int ) is explicit. template<typename ValueType> class Base { public:

SWIG: Wrapping C++ for Perl using only a header and a shared library, can't locate loadable object error

随声附和 提交于 2019-12-19 08:52:08
问题 I'm trying to learn SWIG and I'm having some issues getting SWIG to work with perl on a Linux machine. I have the files Dog.h, Crow.h, Animal.i, and libmylib.so. All these files are in the same directory. libmylib.so was compiled using Dog.cpp and Crow.cpp, which reference Dog.h and Crow.h respectively. My Animal.i file is as follows: %module Animal %{ /* Includes the header in the wrapper code */ #include "Dog.h" #include "Crow.h" %} /*Parse the header file to generate wrappers */ %include

Why can't I compile HelloWorld in C++?

久未见 提交于 2019-12-19 08:44:44
问题 I'm trying to compile a simple Hello World program in C++ but I keep getting the following error...why? gcc -o HelloWorldCompiled HelloWorld.cc /tmp/ccvLW1ei.o: In function `main': HelloWorld.cc:(.text+0xa): undefined reference to `std::cout' HelloWorld.cc:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /tmp/ccvLW1ei.o: In function `__static

Why can't I compile HelloWorld in C++?

眉间皱痕 提交于 2019-12-19 08:44:36
问题 I'm trying to compile a simple Hello World program in C++ but I keep getting the following error...why? gcc -o HelloWorldCompiled HelloWorld.cc /tmp/ccvLW1ei.o: In function `main': HelloWorld.cc:(.text+0xa): undefined reference to `std::cout' HelloWorld.cc:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /tmp/ccvLW1ei.o: In function `__static

Getting undefined reference to std::thread::_M_start_thread

主宰稳场 提交于 2019-12-19 08:28:34
问题 I'm building an app that uses a 3rd party lib (Box2D-MT) which I build from sources. When linking, I get this undefined reference error: b2Threading.cpp:(.text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_[_ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_]+0xa4): undefined reference to 'std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())' I am building with g++ and link with -lBox2D -lpthread -lrt -ldl -lstdc++ also, I am compiling with -std=c++11