gcc

Are std::streams already movable?

GNU gcc 4.3 partially supports the upcoming c++0x standard: among the implemented features the rvalue reference. By means of the rvalue reference it should be possible to move a non-copyable object or return it from a function. Are std::streams already movable by means of rvalue reference or does the current library implementation lack...

Simple C++ code not working

This very simple code gives me tons of errors: #include <iostream> #include <string> int main() { std::string test = " "; std::cout << test; } I tried to compile it on linux by typing gcc -o simpletest simpletest.cpp on the console. I can't see why it isn't working. What is happening? ...

Getting rid of gcc shift by negative warning

I have some code that looks like: template<unsigned int A, unsigned int B> int foo() { int v = 1; const int x = A - B; if (x > 0) { v = v << x; } bar(v); } gcc will complain about x being negative for certain instantiations of A, B; however, I do perform a check to make sure it is non-negative. What's the best way arou...

GCC Fixed Size Integers

On the MSVC++ compiler, one can use the __int8, __int16, __int32 and similar types for integers with specific sizes. This is extremely useful for applications which need to work with low-level data structures like custom file formats, hardware control data structures and the like. Is there a similar equivalent I can use on the GCC compi...

C++ const question.

If I do this: // In header class Foo { void foo(bar*); }; // In cpp void Foo::foo(bar* const pBar) { //Stuff } The compiler does not complain that the signatures for Foo::foo do not match. However if I had: void foo(const bar*); //In header void Foo::foo(bar*) {} //In cpp The code will fail to compile. What is going on? I'm usin...

Will the c++ compiler optimize away unused return value?

If I have a function that returns an object, but this return value is never used by the caller, will the compiler optimize away the copy? (Possibly an always/sometimes/never answer.) Elementary example:ReturnValue MyClass::FunctionThatAltersMembersAndNeverFails() { //Do stuff to members of MyClass that never fails return success...

How to make weak linking work with GCC?

There seem to be 3 ways of telling GCC to weak link a symbol: __attribute__((weak_import)) __attribute__((weak)) #pragma weak symbol_name None of these work for me: #pragma weak asdf extern void asdf(void) __attribute__((weak_import, weak)); ... { if(asdf != NULL) asdf(); } I always get a link error like this: Undefined symbo...

gdb executable file format

I'm trying to use GDB to debug (to find an annoying segfault). When I run: gdb ./filename from the command line, I get the following error: This GDB was configured as "i686-pc-linux- gnu"..."/path/exec": not in executable format: File format not recognized When I execute: file /path/executable/ I get the following info: ELF ...

Dumping the values of the registers in GCC

I need to get the values in the registers with GCC. Something similar to this: EAX=00000002 EBX=00000001 ECX=00000005 EDX=BFFC94C0 ESI=8184C544 EDI=00000000 EBP=0063FF78 ESP=0063FE3C CF=0 SF=0 ZF=0 OF=0 Getting the 32-bit registers is easy enough, but I'm not sure what the simplest way to get the flags is. In the examples ...

How to overcome GCC restriction "could not convert template argument '0' to 'Foo*'"?

Suppose I have code like this: template<class T, T initial_t> class Bar { // something } And then try to use it like this: Bar<Foo*, NULL> foo_and_bar_whatever_it_means_; GCC bails out with error (on the above line): could not convert template argument '0' to 'Foo*' I found this thread: http://gcc.gnu.org/ml/gcc-help/2007...

gcc compiler: How do I enable C++ styled comments while leaving ANSI enabled

This has just come up as a question where I worked so I did a little digging and the answer is a ExpertsExchange one. So I hand you over to the original question asker, Manchung: I have a project written in pure C which is to be used in embedded system. So, I use pure C to minimize the code size. When I compile the project, I us...

How to wait untill all child processes called by fork() complete?

Hi, I am forking a number of processes and I want to measure how long those it take to to complete the whole task, that is when all processes forked are completed. Please advise how to make the parent process to wait until all child process are terminated? I want tu make sure that I stop the time watch in the right moment. Here is as a...

GCC: program doesn't work with compilation option -O3

I'm writing a C++ program that doesn't work (I get a segmentation fault) when I compile it with optimizations (options -O1, -O2, -O3, etc.), but it works just fine when I compile it without optimizations. Is there any chance that the error is in my code? or should I assume that this is a bug in GCC? My GCC version is 3.4.6. Is there a...

Unmangling the result of std::type_info::name

I'm currently working on some logging code that supposed to - among other things - print information about the calling function. This should be relatively easy, standard C++ has a type_info class. This contains the name of the typeid'd class/function/etc. but it's mangled. It's not very usefull. I.e. typeid(std::vector).name() returns "S...

What flag silences GCC's warning about no new-line at file-endings?

I just read this post about why new-line warnings exist, but to be honest my team has people working on several different platforms and with several different editors (everyone uses what bests suites them), so the warning has become ubiquitous, and since its not really a warning worth taking care of it's become Noise and makes finding se...

Finding locations in machine code (gcc/objdump -d)

If you have a particular line of C code in mind to examine in the machine output, how would you locate it in objdump output. Here is an example if (cond) foo; bar(); and I want to see if bar was inlined as I'd like. Or would you use some alternative tool instead of objdump? ...

Using the GCC __unused attribute with Objective-C

Is it possible to use the __unused attribute macro on Objective-C object method parameters? I've tried placing it in various positions around the parameter declaration but it either causes a compilation error or seems to be ignored (i.e., the compiler still generates unused parameter warnings when compiling with -Wall -Wextra). Has anyo...

What can cause strange gcc error "mode_t has not been declared" (and others) in system headers?

This is the compiler message (somewhat stripped): /usr/include/sys/mman.h:145: error: 'mode_t' has not been declared Another error: In file included from /usr/include/sys/resource.h:25, from /usr/include/sys/wait.h:32, /usr/include/bits/resource.h:172: error: field 'ru_utime' has incomplete type /usr/include/bits/res...

How to know (in GCC) when given macro/preprocessor symbol gets declared?

Suppose I have #define foo in various header files. It may expand to some different things. I would like to know (when compiling a .cc file) when a #define is encountered, to what it will expand, it which file it is and where it got included from. Is it possible? If not, are there any partial solutions that may help? Feel free to add c...

How can I use gcc to compile x86 assembly code on an x64 computer

For a school assignment I have to write x86 assembly code, except I can't use gcc to compile it since my computer is an x64 machine, and gcc is only excpecting x86 code. Is there a command that'll make gcc accept it x86 assembly code? Thanks P.S. I know my code is valid since it compiles just fine on x86 machines. ...