g++

Reference-counting of std::string

I'm looking at the code for basic_string (that is bundled with g++ 4.2.1). The copy constructor makes use of a grab() function to "grab" a copy of a string (increment its reference-count): _CharT* _M_grab( const _Alloc& __alloc1, const _Alloc& __alloc2 ) { return (!_M_is_leaked() && __alloc1 == __alloc2) ? _M_refcopy() : _M_clone(__a...

g++ linking order dependency when linking c code to c++ code.

Prior to today I had always believed that the order that objects and libraries were passed to g++ during the linking stage was unimportant. Then, today, I tried to link from c++ code to c code. I wrapped all the C headers in an extern "C" block but the linker still had difficulties finding symbols which I knew were in the C object archiv...

const member isn't explicitly initialized but compiles

I heard that const members must be explicitly intialized, but the following compiles for me: class someClass { int const x; }; int main() { return 0; } ...

Variadic templates for lambda expressions

What's the correct way to do this with g++: template < typename F > void g (F f); template < typename ... A > void h (A ... a); template < typename ... A > void f (A ... a) { g ([&a] () { h (a...); }); // g++-4.6: error: parameter packs not expanded with »...« } ...

Tiny crashing program

The following program compiles with g++ but then crashes upon running: class someClass { public: int const mem; someClass(int arg):mem(arg){} }; int main() { int arg = 0; someClass ob(arg); float* sample; *sample = (float)1; return 0; } The following program does not crash: int main() { float* samp...

Using g++ to compile, how do I point it to other .h files?

I'm trying to compile a .cpp + .h file that includes newmat.h and tinyxml.h - I have libnewmat.a and libtinyxml.a in the same directory as my .cpp and .h files and I'm running g++ -lnewmat -ltinyxml test.cpp test.h but still getting newmat.h and tinyxml.h not found at the beginning of compilation. I'm obviously a total c++ newb becau...

How to speed up g++ compile time (when using a lot of templates)

This question is perhaps somehow odd, but how can I speed up g++ compile time? My C++ code heavily uses boost and templates. I already moved as much as possible out of the headers files and use the -j option, but still it takes quite a while to compile (and link). Are there any tools out there which analyse my code and point out bottle-...

How do I set GNU G++ compiler in Visual studio 2008

How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer. Thank you. ...

Omitting return statement in C++

I just had some weird behavior from a version of g++ for Windows that I got with Strawberry Perl. It allowed me to omit a return statement. I have a member function that returns a structure consisting of two pointers, called a boundTag: struct boundTag Box::getBound(int side) { struct boundTag retBoundTag; retBoundTag.box = thi...

Inclusion problem

I have an inclusion pattern as follows: /* * Class1.h */ #ifndef CLASS1_H_ #define CLASS1_H_ #include "Class2.h" namespace Class1_namespace { class Class1 { Class2* Class2_ptr; void Class1_member() { (*Class2_ptr).Class2_method(); } }; } #endif /* CLASS1_H_ */ /* * Class2.h */ #ifndef CLASS2_H_ #define CLASS2_H...

Maintaining ABI: adding constructor to struct

We have a struct in revision 1 of a shared library that we need to maintain the ABI for: struct Person { std::string first_name; std::string last_name; } In the revision 2, we're changing Person to this: class Person { public: Person(const std::string &f, const std::string &l); std::string first_name; std::string...

How does one suppress specific warnings from source code on g++ 4.5 or later?

The first comment on a feature request for g++ says, "Starting with 4.5 you can disable a class of warnings in the source." I looked through the 4.5.0 manual, but I can't find the syntax. What is the syntax in g++ 4.5 and later to suppress individual warning classes in the source? ...

how to build g++

I'm currently trying to get g++ working, and looking at http://gcc.gnu.org/install/build.html, I can't seem to find where it says how "to perform a 3-stage bootstrap of the compiler". Where would I find this information? (I'm on a mac, in case that matters.) ...

Can I write an interface for a template class in C++

I have an interface and a couple of implementations of a class that stores serialized objects. I'd like to make the implementation classes into template classes so I can use them with more than one type of object, but I'm getting compiler errors. #include <iostream> template<typename T> class Interface{ public: virtual void func...

Help with explaining profiler results [STL]

Hi guys, I'm profiling a recent program that is dominated with File read. I'm kind of confused on how to interpret the results. If someone could explain to me what these top four functions are, it would help me a lot. Thanks in advance! % cumulative self self total time seconds seconds calls ...

Can I use a SFINAE test in a control flow statement?

I have an SFINAE test for checking if an class has a function. The test works correctly, but I get compiler errors when I try to use it in an if statement. //SFINAE test for setInstanceKey() template <typename K> class HasSetInstanceKey { template <typename C> static char test( typeof(&C::setInstanceKey) ); template <typen...

using openmp with a makefile and g++

I am building a large project with a makefile that was originally built with icpc, and now I need to get it running with g++. When it compiles the file that uses openmp, it uses the -c flag, and doesn't use any libraries, so it ends up being serial instead of openmp. All of the examples I am seeing aren't using this -c flag. Is there s...

Can gcc/g++ tell me when it ignores my register?

When compiling C/C++ codes using gcc/g++, if it ignores my register, can it tell me? For example, in this code int main() { register int j; int k; for(k = 0; k < 1000; k++) for(j = 0; j < 32000; j++) ; return 0; } j will be used as register, but in this code int main() { register int j; int...

undefined reference to `Class::Class()'

Hello, I am writing a GTKmm window program; the main window creates two buttons, one for English and one for Chinese. The user can click on the button to bring up a different window in the appropriate language. Currently I am having trouble initializing the multiple-item container inside the main window. It is an object of type MainWindo...

Can you lookup where a typedef is being defined?

Is it possible to lookup where a typedef is being defined? I am running into this very evasive problem that is producing the following compiler error: /usr/include/stdint.h: At global scope: /usr/include/stdint.h:57: error: duplicate 'unsigned' /usr/include/stdint.h:57: error: declaration does not declare anything where /usr/include/...