g++

binary object file changing in each build

家住魔仙堡 提交于 2019-12-17 17:06:19
问题 When compiling using G++ GNU compiler every time I do a build, without changing source code I get a different binary object file. Is there a compile option that will give me the same binary each time. 回答1: Copied from the GCC man-page: -frandom-seed=string This option provides a seed that GCC uses when it would otherwise use random numbers. It is used to generate certain symbol names that have to be different in every compiled file. It is also used to place unique stamps in coverage data

“Unresolved overloaded function type” while trying to use for_each with iterators and function in C++

末鹿安然 提交于 2019-12-17 16:36:36
问题 //for( unsigned int i=0; i < c.size(); i++ ) tolower( c[i] ); for_each( c.begin(), c.end(), tolower ); I am trying to use a for_each loop in place of the for loop for an assignment. I am unsure why I am getting this error message: In function âvoid clean_entry(const std::string&, std::string&)â: prog4.cc:62:40: error: no matching function for call to âfor_each(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â 回答1: Write: for_each( c

Difference between regex_match and regex_search?

▼魔方 西西 提交于 2019-12-17 16:35:15
问题 I was experimenting with regular expression in trying to make an answer to this question, and found that while regex_match finds a match, regex_search does not. The following program was compiled with g++ 4.7.1: #include <regex> #include <iostream> int main() { const std::string s = "/home/toto/FILE_mysymbol_EVENT.DAT"; std::regex rgx(".*FILE_(.+)_EVENT\\.DAT.*"); std::smatch match; if (std::regex_match(s.begin(), s.end(), rgx)) std::cout << "regex_match: match\n"; else std::cout << "regex

In g++ is C++ 11 thread model using pthreads in the background?

瘦欲@ 提交于 2019-12-17 16:34:01
问题 I am just trying my hands on g++ 4.6 and C++11 features. Every time I compile a simple threading code using -std=c++0x flag, either it crashes with segmentation fault or it just throws some weird exception. I read some questions related to C++11 threads and I realized that, I also need to use -pthread flag to compile the code properly. Using -pthread worked fine and I was able to run the threaded code. My question is, whether the C++11 multi-threading model uses Pthreads in the background? Or

How to suppress specific warnings in g++

爱⌒轻易说出口 提交于 2019-12-17 16:24:56
问题 I want to suppress specific warnings from g++. I'm aware of the -Wno-XXX flag, but I'm looking for something more specific. I want some of the warnings in -Weffc++ , but not all of them. Something like what you can do with lint - disable specific messages. Is there a built in way in gcc to do this? Do I have to write a wrapper script? 回答1: Unfortunately, this feature isn't provided by g++. In VC++, you could use #pragma warning to disable some specific warnings. In gcc, the closest you can

Do I really have to worry about alignment when using placement new operator?

六眼飞鱼酱① 提交于 2019-12-17 15:39:27
问题 I read this When should I worry about alignment? but I am still do not know if I have to worry about not aligned pointer returned by placement new operator - like in this example: class A { public: long double a; long long b; A() : a(1.3), b(1234) {} }; char buffer[64]; int main() { // (buffer + 1) used intentionally to have wrong alignment A* a = new (buffer + 1) A(); a->~A(); } __alignof(A) == 4 , (buffer + 1) is not aligned to 4 . But everything works fine - full example here: http:/

What's the point of g++ -Wreorder?

雨燕双飞 提交于 2019-12-17 15:10:01
问题 The g++ -Wall option includes -Wreorder. What this option does is described below. It is not obvious to me why somebody would care (especially enough to turn this on by default in -Wall). -Wreorder (C++ only) Warn when the order of member initializers given in the code does not match the order in which they must be executed. For instance: struct A { int i; int j; A(): j (0), i (1) { } }; The compiler will rearrange the member initializers for i and j to match the declaration order of the

Why does sqrt() work fine on an int variable if it is not defined for an int?

安稳与你 提交于 2019-12-17 14:45:49
问题 In chapter 3 of Programming: Principles and Practice using C++ (sixth printing), Stroustrup states (p.68): "Note that sqrt() is not defined for an int " . Here is a simple C++ program based on that chapter: #include "std_lib_facilities.h" int main() { int n = 3; cout << "Square root of n == " << sqrt(n) << "\n"; } Given the quote above, I would expect the process of compiling or running this program to fail in some way. To my surprise, compiling it (with g++ (GCC) 4.2.1) and running it

How to make G++ preprocessor output a newline in a macro?

僤鯓⒐⒋嵵緔 提交于 2019-12-17 11:21:15
问题 Is there a way in gcc/g++ 4.* to write a macro that expands into several lines? The following code: #define A X \ Y Expands into X Y I need a macro expanding into X Y 回答1: Got it! #define anlb /* */ A /* */ B anlb anlb gcc -E -CC nl.c /* */ A /* */ B /* */ A /* */ B 回答2: Make the macro generate a special markup, say __CR__ , then pipe the result of CPP into a script which translates the macro to a true newline, for example, sed 's/__CR__/\n/g' . I just found this useful to generate a code

Object file has too many sections

a 夏天 提交于 2019-12-17 10:44:32
问题 We am making heavy use of boost::serialization and templates in general. All seems to be going well. Except, we've hit a snag on our Windows builds. It seems to cause issues in the object files being too large. We're using MinGW/Msys with g++ 4.7.0. c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/as.exe: CMakeFiles/source.dir/sourcecode.cpp.obj: too many sections (33396) C:\Users\username\AppData\Local\Temp\ccnAocvD.s: Assembler messages: C:\Users\username\AppData\Local\Temp