gcc

Using GCC from within VS 2005(8) IDE

Is there a way to utilise the GCC compiler whilst still being able to develop via the Visual Studio IDE? Our project is cross-platform, and I quite frequently get into trouble from my colleague because I'm checking in code that's not standards compliant (this can be attributed to the VS compiler!). I'd still like to be able to compil...

How to import homepath into c program using gcc

I am using gcc for windows. The OS is windows XP. How do I import the homepath variable into my c program so I can write to c:\%homepath%\desktop? I would like to use something similar to: fd = fopen("C:\%%homepath%%\desktop\helloworld.txt","w"); ...

Compile-time LCM / GCD in C

Does anyone know a mechanism to calculate at compile-time the LCM (Least Common Multiple) and/or GCD (Greatest Common Denominator) of at least two number in C (not C++, I know that template magic is available there)? I generally use GCC and recall that it can calculate certain values at compile-time when all inputs are known (ex: sin, c...

How to generate a stacktrace when my gcc C++ app crashes

When my c++ app crashes I would like to generate a stacktrace. I already asked this but I guess I needed to clarify my needs. My app is being run by many different users and it also runs on Linux, Windows and Macintosh ( all versions are compiled using gcc ). I would like my program to be able to generate a stack trace when it crashes...

Need gcc/g++ working on SCO6

Has anyone found a way to get gcc to build/install on SCO6? With 2.95 and 4.3 I get to the point where it needs to use (2.95) or find (4.3) the assembler and that's where it fails. If anyone has figured this out I would appreciate the info! Thanks ...

"foreach values" macro in gcc & cpp

I have a 'foreach' macro I use frequently in C++ that works for most STL containers: #define foreach(var, container) \ for(typeof((container).begin()) var = (container).begin(); \ var != (container).end(); \ ++var) (Note that 'typeof' is a gcc extension.) It is used like this: std::vector< Blorgus > blorgi = ...; foreac...

scanf() (and cin) statements skipped when using gcc.

When multiple scanf() statements are encountered in the code, then, except the first scanf() statement, all others are skipped, that is, there is no prompt for input for those scanf() statements when the code is run. I have a tried a few suggestions. For eg, use of flushall() was suggested on some site, but that gives a compilation erro...

Do I have a gcc optimization bug or a C code problem?

Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext="0"; const float f=(float)atof(yytext); size_t t = *((size_t*)&f); printf("t should be 0 but is %d\n", t); } Compile it with: gcc -O3 test.c The GOOD output should be: "t should be 0 but is 0" But with my gcc 4.1.3, I have...

How does gcc implement stack unrolling for C++ exceptions on linux?

How does gcc implement stack unrolling for C++ exceptions on linux? In particular, how does it know which destructors to call when unrolling a frame (i.e., what kind of information is stored and where is it stored)? ...

How Does The Debugging Option -g Change the Binary Executable?

When writing C/C++ code, in order to debug the binary executable the debug option must be enabled on the compiler/linker. In the case of GCC, the option is -g. When the debug option is enabled, how does the affect the binary executable? What additional data is stored in the file that allows the debugger function as it does? ...

What is the difference between gcc optimization levels?

What is the difference between different optimization levels in GCC? Assuming I don't care to have any debug hooks, why wouldn't I just use the highest level of optimization available to me? does a higher level of optimization necessarily (i.e. provably) generate a faster program? ...

gcc dependency generation for a different output directory

I'm using gcc to generate a dependency file but my build rules put the output into a subdirectory. Is there a way to tell gcc to put my subdirectory prefix in the dependency file it generates for me? gcc $(INCLUDES) -E -MM $(CFLAGS) $(SRC) >>$(DEP) ...

Why Am I Getting Link Errors When Calling Function in Math.h?

When attempting to call functions in math.h, I'm getting link errors like the following undefined reference to sqrt But I'm doing a #include <math.h> I'm using gcc and compiling as follows: gcc -Wall -D_GNU_SOURCE blah.c -o blah Why can't the linker find the definition for sqrt? ...

Is there a good general method for debugging C++ macros?

In general, I occasionally have a chain of nested macros with a few preprocessor conditional elements in their definitions. These can be painful to debug since it's hard to directly see the actual code being executed. A while ago I vaguely remember finding a compiler (gcc) flag to expand them, but I had trouble getting this to work in ...

GCC compiling a dll with __stdcall

When we compile a dll using __stdcall inside visual studio 2008 the compiled function names inside the dll are. FunctionName Though when we compile the same dll using GCC using wx-dev-cpp GCC appends the number of paramers the function has, so the name of the function using Dependency walker looks like. FunctionName@numberOfParameters...

How to simulate memory allocation errors

My C application uses 3rd libraries, which do their own memory management. In order to be robust, my application has code to deal with failures of library functions due to lack of free memory. I would like to test this code, and for this, I need to simulate failures due to lack of memory. What tool/s are recommended for this? My enviro...

likely/unlikely macros in the Linux kernel

I've been digging through some parts of the Linux kernel, and found calls like this: if (unlikely(fd < 0)) { /* Do something */ } or if (likely(!err)) { /* Do something */ } I've found the definition of them: #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) I know that they ...

GCC optimization flags for Intel Atom

I'm developing a performance critical application for Intel Atom processor. What are the best gcc optimization flags for this CPU? ...

Which gcc switch disables "left-hand operand of comma has no effect" warning?

It's a part of larger code base, which forces -Werror on gcc. This warning is generated in a third party code that shouldn't be changed (and I actually know how to fix it), but I can disable specific warnings. This time man gcc failed me, so please, let some gcc master enlighten me. TIA. ...

Is there a way to install gcc in OSX without installing Xcode?

I've googled the hell out of it, and it seems like there is no way to install gcc on OS X without installing Xcode (which takes at leats 1.5GB of space). All I need is gcc and none of the other junk that comes with Xcode. And at this point, I'll take any other kind of C compiler. I know I could simply install Xcode, but that is beside t...