g++

Optimization and flags for making a static library with g++

妖精的绣舞 提交于 2019-12-20 08:03:31
问题 I am just starting with g++ compiler on Linux and got some questions on the compiler flags. Here are they Optimizations I read about optimization flags -O1 , -O2 and -O3 in the g++ manual page. I didn't understood when to use these flags. Usually what optimization level do you use? The g++ manual says the following for -O2 . Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function

Does g++ work without gcc?

大城市里の小女人 提交于 2019-12-20 07:55:14
问题 Does G++ compile without GCC or G++ is just translator // Including old g++ version. when i was trying to install g++ from source i saw file gcc.c /* Default prefixes to attach to command names. */ #ifndef STANDARD_EXEC_PREFIX #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-" #endif /* !defined STANDARD_EXEC_PREFIX */ //from g++1.4* Well i know that c++ is c with classes i just wanted to know if the g++ can compile c++ without gcc . 回答1: With a recent GCC, gcc (actually cc1 which is run by

Does g++ work without gcc?

。_饼干妹妹 提交于 2019-12-20 07:54:19
问题 Does G++ compile without GCC or G++ is just translator // Including old g++ version. when i was trying to install g++ from source i saw file gcc.c /* Default prefixes to attach to command names. */ #ifndef STANDARD_EXEC_PREFIX #define STANDARD_EXEC_PREFIX "/usr/local/lib/gcc-" #endif /* !defined STANDARD_EXEC_PREFIX */ //from g++1.4* Well i know that c++ is c with classes i just wanted to know if the g++ can compile c++ without gcc . 回答1: With a recent GCC, gcc (actually cc1 which is run by

What is the need to generate ASM code in gcc, g++

◇◆丶佛笑我妖孽 提交于 2019-12-20 07:35:41
问题 To narrow down my question, let me describe my assumption and the experiment that I did... My assumption: A code written in assembly language will run much faster than its C/C++ counterpart and also the executable size to be much smaller than that generated from C/C++ code. The experiment: I wrote the below program in to bin2dec.c #include <stdio.h> int main() { long int binary, decimal, reminder, exp; int i, j; for(i=0; i<10000; i++) { for(j=0; j<1000; j++) { binary = 11000101; exp = 1;

g++ warning on declaring multidimensional, double array

青春壹個敷衍的年華 提交于 2019-12-20 04:12:45
问题 In my C++ program I am trying to initialize a 3*3*3 array of type double with all 0's. In the class header file, I declared a member double list[3][3][3]; When I printed out the content of this array, I found that not all entries are 0 as I expected. e.g. list[1][1][1] has value 4.03158e-321 Hence I manually initialized this array to all 0's in the constructor: list = {{{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0}}, {{0,0,0},{0,0,0},{0,0,0}}}; This makes my program work, however, I got

Overloading operator<<: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’

情到浓时终转凉″ 提交于 2019-12-20 03:56:37
问题 Searching for the title of this question gives me a number of people quoting the same error, but under different circumstances, and unfortunately the answers there provided are specific to their situation, and I do not see how they can help me. I am trying to overload operator<< for a template class. Following is a test case: Vector.h: #ifndef __INCL_VECTOR_H__ #define __INCL_VECTOR_H__ #include <array> template < class T, unsigned int N > class Vector { public: Vector(); Vector( std::array<

Why can't I initialize an array of objects if they have private copy constructors?

99封情书 提交于 2019-12-20 03:51:03
问题 I just ran across some unexpected and frustrating behaviour while working on a C++ project. My actual code is a tad more complicated, but the following example captures it just as well: class Irritating { public: Irritating() {} private: Irritating(const Irritating& other) {} }; const Irritating singleton; // Works just fine. const Irritating array[] = {Irritating()}; // Compilation error. int main() { return 0; } Trying to compile this produces the following error (GCC version thrown in just

Why does not std::nothrow work as expected in gcc(4.9)?

荒凉一梦 提交于 2019-12-20 03:23:34
问题 I've seen lots of people in my team checking null pointers like this: SomeClass *pSc = new SomeClass; if ( NULL == pSc ) { // cope with error } I known this will not work, because new operator in c++ throws a std::bad_alloc exception instead of returning NULL. I also know that std::nothrow can make what they expected really happen. So I wrote an example like this: #include <iostream> #include <limits> #include <new> using namespace std; void myNewHandler() { std::cerr << "Failed to allocate

G++ can't find references to raw() or cbreak(), even when linking curses [duplicate]

荒凉一梦 提交于 2019-12-20 03:20:01
问题 This question already has an answer here : DSO missing from command line [duplicate] (1 answer) Closed 2 years ago . I'm having trouble getting some absolute basic work with curses.h done, even though I've worked with it before. I'm sure it's a classic case of missing something small, but I'm at my wit's end. G++ absolutely won't recognize the functions raw() or cbreak(), even though curses.h is included in my .cpp and header file, and linked to when compiling with (minimal version): g++

C++ calculating time intervals

心不动则不痛 提交于 2019-12-20 03:09:09
问题 I want to calculate time intervals (in 1/10th of 1 second) between some events happening in my program. Thus I use clock function for these needs like follows: clock_t begin; clock_t now; clock_t diff; begin = clock(); while ( 1 ) { now = clock(); diff = now - begin; cout << diff / CLOCKS_PER_SEC << "\n"; //usleep ( 1000000 ); }; I expect the program to print 0 for 1 second, then 1 for 1 sec., then 2 for 1 sec. and so on... In fact it prints 0 for about 8 seconds, then 1 for about 8 seconds