g++

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

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...

boost::any test code compiles with Sun CC but not g++

The following noddy test code: #include <iostream> #include <list> #include <boost/any.hpp> #include <boost/foreach.hpp> #include <typeinfo.h> using boost::any_cast; using std::cout; using std::cerr; typedef std::list<boost::any> many; template <typename T> inline bool is_any(const boost::any& op) { return (op.type() == typeid(T)); ...

Linking an application to libbz2.so.1 rather than libbz2.so.1.0

Here's the current situation I'm in: I want to distribute a binary app on Linux that would run on several distros (not all of them, just the main ones matter at the moment, let's focus on Ubuntu and Fedora for the sake of this discussion). The app in question links to libbz2 for some of its work. A simple "Hello World" will illustrate t...

name collision in C++

Hi all, While writing some code i came across this issue: #include <iostream> class random { public: random(){ std::cout << "yay!! i am called \n" ;} }; random r1 ; int main() { std::cout << "entry!!\n" ; static random r2; std::cout << "done!!\n" ; return 0 ; } When i try to compile this code i get the error error: ârandomâ d...

Why doesn't this compile?

When I try to declare iss using the first form, g++ gives me "error: no match for 'operator>>' in 'iss >> s'". But don't the two different declarations do the same thing? #include <iostream> #include <sstream> #include <string> int main() { const char *buf = "hello world"; std::string ss(buf); //std::istringstream iss(std:...

Assigning a "const char*" to std::string is allowed, but assigning to std::wstring doesn't compile. Why?

I assumed that std::wstring and std::string both provide more or less the same interface. So I tried to enable unicode capabilities for our application # ifdef APP_USE_UNICODE typedef std::wstring AppStringType; # else typedef std::string AppStringType; # endif However that gives me a lot of compile errors when -DAPP_USE_UNI...

Is it allowed to inherit from a class in the std namespace (namely std::wstring)?

The class std::wstring is missing some operations for "normal" c strings (and literals). I would like to add these missing operations in my own custom class: #include <string> class CustomWString : public std::wstring { public: CustomWString(const char*); const char* c_str(void); }; The code above c...

Linking in Xcode

How do I make Xcode link object files properly? The file containing "main" and all the dependencies compile properly (and I can easily link them in the command line to generate the executable). However, Xcode seems to refuse to do it, resulting in ld errors of "symbol not found". This is what my current setup looks like. All the depend...

Generic VC++ vs g++ query

I have trouble understanding the compilers. The following code does work in UNIX under g++, but under VC++ it would not even compile. Anyone can provide valid reasons why? #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int main() { string tmp_nw_msg, crc_chksum, buffer; cout << "Enter the str...

Problem with class template specialisations

I'm trying to port some code from VC9 to G++, however Ive run into a problem with template specialisations apparently not being allowed for class members. The following code is an example of these errors for the getValue specialisations of the class methods. In all cases the error is "error: explicit specialization in non-namespace scop...

g++ linker segment

Hi, Is it possible to specify what linker segment that a piece of code in a c++ source file will reside in? For example, int foo() { ... } ---> place in Link Segment A int bar() { ... } ---> place in Link Segment B I vaguely recall some source code like the following codea_ int foo () { ... } Any ideas? Thanks! ...

valgrind report memory leak when assign a value to a string

Valgrind report memory leak when assign a value to a string I used this simple code to test an memory leak reported by valgrind. /****************************************** * FILE: t3.c * Compiled using : g++ -g t3.c -o t3 * * $ g++ -v * Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.6/specs * Configured with: ./configure --pre...

dynamic linking msvc compiled dlls in g++

Very sorry if this question has been asked numerous times, but I can not find a precise reference :( The problem is: I have a DLL file along with corresponding LIB file compiled with VC++ 08. Now I want to dynamically link it with another application I am compiling using g++. Is it possible? What linker options will I have to give in ...

G++ not finding <iostream.h> in Ubuntu

I just installed Ubuntu and tried making the famed "Hello World" program to make sure that all the basics were working. For some reason though, g++ fails to compile my program with the error: "'cout' is not a member of 'std'". I've installed the build-essential package. Am I missing something else? #include <iostream.h> int main() {...

Warning for Missing Virtual Keyword

I had a frustrating problem recently that boiled down to a very simple coding mistake. Consider the following code: #include <iostream> class Base { public: void func() { std::cout << "BASE" << std::endl; } }; class Derived : public Base { public: virtual void func() { std::cout << "DERIVED" << std::endl; } }; int main(int a...

x86: howto catch data-alignment faults (aka SIGBUS on sparc)

Is it somehow possible to catch data-alignment faults even on i386? Maybe by setting a i386 specific machine register or something like that. On Solaris-Sparc I am receiving a SIGBUS in this case, but on i386 everything is fine. Environment: 32-bit application Ubuntu Karmic gcc/g++ v4.4.1 EDIT: Here is why I am asking this: our ...

What are the gcc preprocessor flags for the compiler's version number?

I have run into a bug with gcc v3.4.4 and which to put an #ifdef in my code to work around the bug for only that version of the compiler. What are the GCC compiler preprocessor flags to detect the version number of the compiler? Thanks. ...

segmentation fault when using pthreads , in a nondeterministic manner

The problem is that when I run the code below, on a single core, sometimes it runs correctly,and sometimes I get segmentation fault. Probably this problem will occure more frequently on a multi-core machine. I need to know where this non-determinism is introduces in my program and how can I resolve it.thanks. int numThreads = 4; class...

Why is g++ saying 'no match for ‘operator=’ when there clearly is, and Visual Studio can see that there is?

I'm writing an interface library that allows access to variables within tables (up to a theoretically infinite depth) in an object of type regula::State. I'm accomplishing this by overloading operator[] within a class, which then returns another of that same class, and calls operator[] again as needed. For example: regula::State t; t["m...

g++: warning: integer constant is too large for ‘long’ type

What can I do (programmatically) to get rid of the warning? ... unsigned long long v=(unsigned long long)0xffffeeeeddddcccc; ... g++ main.cpp -o main main.cpp:6: warning: integer constant is too large for ‘long’ type but when I run the program everything is fine as expected: ./main sizeof(unsigned long long)==8 value of v==0x...