gcc

Why doesn't GCC optimize structs?

Systems demand that certain primitives be aligned to certain points within the memory (ints to bits that are multiples of 4, shorts to bits that are multiples of 2, etc.). Of course, these can be optimized to waste the least space in padding. my question is why doesn't GCC do this automatically? Is the more obvious heuristic (order va...

GCC inline assembler, mixing register sizes (x86)

Does anyone know how I can get rid of the following assembler warning? Code is x86, 32 bit: int test (int x) { int y; // do a bit-rotate by 8 on the lower word. leave upper word intact. asm ("rorw $8, %0\n\t": "=q"(y) :"0"(x)); return y; } If I compile it I get the following (very valid) warning: Warning: using `%ax' instead...

Performance improvements moving from g++/gcc 3.2.3 to 4.2.4.

We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance improvements on some of our code base is significant. I've tried searching the gcc buzilla database to find hints as to what bugs may have had such a dramatic improvement but I didn't find any individual bug that stood out as being a candidate. Are the i...

How to get GCC to use more than two SIMD registers when using intrinsics?

I am writing some code and trying to speed it up using SIMD intrinsics SSE2/3. My code is of such nature that I need to load some data into an XMM register and act on it many times. When I'm looking at the assembler code generated, it seems that GCC keeps flushing the data back to the memory, in order to reload something else in XMM0 an...

Is it possible to subclass a C struct in C++ and use pointers to the struct in C code?

Is there a side effect in doing this: C code: struct foo { int k; }; int ret_foo(const struct foo* f){ return f.k; } C++ code: class bar : public foo { int my_bar() { return ret_foo( (foo)this ); } }; There's an extern "C" around the C++ code and each code is inside its on compilation unit. Is this p...

GNU compiler warning "class has virtual functions but non-virtual destructor"

I have defined an interface in c++, i.e. a class containing only pure virtual functions. I want to explicitly forbid users of the interface to delete the object through a pointer to the interface, so I declared a protected and non-virtual destructor for the interface, something like: class ITest{ public: virtual void doSomething() ...

Link error when compiling gcc atomic operation in 32-bit mode

I have the following program: ~/test> cat test.cc int main() { int i = 3; int j = __sync_add_and_fetch(&i, 1); return 0; } I'm compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine: ~/test> uname --all Linux doom 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:56:44 EST 2007 x86_64 x86_64 x86_64 GNU/Lin...

C++ tr1 on GCC 3.4.4 (for the Nokia N810 tablet computer)

What does it take to get C++ tr1 members (shared_ptr especially, but we'd like function and bind and ALL the others) working with GCC 3.4.4 (for the Nokia N810 tablet computer). Has anyone done this? Attempted this? It may not be feasible for us to upgrade to GCC 4.x to cross-compile for this device (but if you've done that, we'd ...

How to Google for --depend?

The latest makefiles we've received from a third party vendor contain rules with --depend on the end of build rules, so I thought I would look it up on Google, but try as I might, I can't persuade it to display any pages with exactly the characters --depend I've tried surrounding it with quotes "--depend": I've tried the Advanced Search...

How do you get assembler output from C/C++ source in gcc?

How does one do this? If I want to analyze how something is getting compiled, how would I get the emitted assembly code? ...

gcc3.3 undefined reference to std::_Rb_tree<>::insert_unique

I'm building a shared library with g++ 3.3.4. I cannot link to the library because I am getting ./BcdFile.RHEL70.so: undefined symbol: _ZNSt8_Rb_treeIjjSt9_IdentityIjESt4lessIjESaIjEE13insert_uniqueERKj Which c++filt describes as std::_Rb_tree<unsigned int, unsigned int, std::_Identity<unsigned int>, std::less<unsigned int>, std::a...

linker woes - undefined reference

Hi! I'm having a problem with my compiler telling me there is an 'undefined reference to' a function I want to use in a library. Let me share some info on the problem: I'm cross compiling with gcc for C. I am calling a library function which is accessed through an included header which includes another header, which contains the proto...

Nintendo DS homebrew with Ada?

Note: I know very little about the GCC toolchain, so this question may not make much sense. Since GCC includes an Ada front end, and it can emit ARM, and devKitPro is based on GCC, is it possible to use Ada instead of C/C++ for writing code on the DS? Edit: It seems that the target that devKitARM uses is arm-eabi. ...

DLL-s using C++ on Linux

I have tried to find how to create DLL-s on linux using google, but got very confusing information. Is it possible to write dynamic link libraries on linux? If not, are there other means by which I can call code in another module from several running programs? ...

Using pre-compiled headers with CMake

I have seen a few (old) posts on the 'net about hacking together some support for pre-compiled headers in CMake. They all seem a bit all-over the place and everyone has their own way of doing it. What is the best way of doing it currently? ...

Setting per-file flags with automake

Is there a way set flags on a per-file basis with automake? In particular, if I have a c++ project and want to compile with -WAll all the files except one for which I want to disable a particular warning, what could I do? I tried something like: CXXFLAGS = -WAll ... bin_PROGRAMS = test test_SOURCES = main.cpp utility.cpp utility_o_CXXF...

Optimising C++ 2-D arrays

I need a way to represent a 2-D array (a dense matrix) of doubles in C++, with absolute minimum accessing overhead. I've done some timing on various linux/unix machines and gcc versions. An STL vector of vectors, declared as: vector<vector<double> > matrix(n,vector<double>(n)); and accessed through matrix[i][j] is between 5% and 100...

Converting a pointer into an integer

I am trying to adapt an existing code to a 64 bit machine. The main problem is that in one function, the previous coder uses a void* argument that is converted into suitable type in the function itself. A short example: void function(MESSAGE_ID id, void* param) { if(id == FOO) { int real_param = (int)param; // ... ...

GUIDs in a C++ Linux GCC app

I've got a bunch of servers running this Linux app. I'd like for them to be able to generate a GUID with a low probability of collision. I'm sure I could just pull 128 bytes out of /dev/urandom and that would probably be fine, but is there a simple & easy way to generate a GUID that is more equivalent to the Win32 one? Specifically, o...

Recommended gcc warning options for C

Other than -Wall what other warnings have people found useful? http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Warning-Options.html ...