gcc

How many GCC optimization levels are there?

How many GCC optimization levels are there? I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4 If I use a really large number, it won't work. However, I have tried gcc -O100 and it compiled. How many optimization levels are there? ...

How to get gcc -O1 optimization without specifying -O1

I know that -O1 automatically turns on certain flags. These flags can be turned on manually though. If I don't specify -O1, it should still be possible to get -O1 optimization by specifying all the flags that -O1 turns on. I tried -fthread-jumps -fcprop-registers -fguess-branch-probability but it still does not do -O1 optimization....

How to turn off specific optimization flags in gcc

I want to compile with optimization -O1, but there is a certain flag that it turns on that I do not want to use. How do I turn it off? ...

Weird result printing pointers as float in C

I know this is wrong and gcc will give you a warning about it, but why does it work (i.e. the numbers are printed correctly, with some rounding difference)? int main() { float *f = (float*) malloc(sizeof(float)); *f = 123.456; printf("%f\n", *f); printf("%f\n", f); return 0; } Edit: Yes, I'm using gcc with a 32-bit mach...

Linking against Apple frameworks with gcc

I've created some wrapper functions that encapsulate working with CoreAudio, and the goal is to create a C library that I can use with some command line C++ tools. So far things are working well. I took a sample project, modified it, and it builds and runs in XCode. I'd like to skip XCode altogether and build the library with gcc and ...

Why does gcc report "implicit declaration of function ‘round’"?

I have the following C code: #include <math.h> int main(int argc, char ** argv) { double mydouble = 100.0; double whatever = round(mydouble); return (int) whatever; } When I compile this, I get the warnings: round_test.c: In function ‘main’: round_test.c:6: warning: implicit declaration of function ‘round’ round_test.c:...

Does the Visual Studio C compiler have an equivalent to GCC's -M?

I would like to automatically generate a Makefile dependency list, but I am using Visual Studio 2005. If I were using GCC, I could pass -M (or one of the many variants) to create this dependency list. Looking through the command line options to cl.exe, I don't see anything obvious. I can handle tweaking the output with post-processing,...

Shared Library Path as Executable Directory

Hi, I have an application that is broken into several libraries for purposes of code reuse. On Windows all I have to do is put the .dll files in the same path as the executable and it automatically finds them. On Linux (since it hardcodes the paths to things) I have to specify the environmental variable LD_LIBRARY_PATH or preload the ...

How does make know which files to update

I noticed that when I make changes to some files and then I type make, it will run certain commands related to those files. If I don't change anything, then make doesn't do anything, saying that the program is up to date. This tells me that make has a way of knowing which files were changed since it was last run. How does it know? It...

Why does GCC give me a syntax error when trying to return a struct pointer?

I'm using CodeLite on Ubuntu and for some bizzare reason GCC keeps throwing this error whenever I try to compile code with a function that returns a pointer to a struct: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token Here is an example I wrote up to demonstrate this error: #include <stdio.h> typedef struct ...

predeclaration in c++

I have a program for distance vector routing as shown below (though, what the program is for is not important here). The problem is when I run this program using Turbo C++ compiler on Windows, it works perfectly fine. But when I compile this using gcc on Fedora 9 (as you can see the 'r' I have used in the function build of the 'router' ...

C - the limits of speed of the Desktop-CPUs if program is build using GCC with all optimization flags?

We are planning to port a big part of our Digital Signal Processing routines from hardware-specific chips to the common desktop CPU architecture like Quad-Core or so. I am trying to estimate the limits of such architecture for a program build with GCC. I am mostly interested in a high SDRAM-CPU bandwidth [Gb/sec] and in a high number of ...

Fast Image Manipulation using SSE instructions?

I am writing a graphics library in C and I would like to utilize SSE instructions to speed up some of the functions. How would I go about doing this? I am using the GCC compiler so I can rely on compiler intrinsics. I would also like to know whether I should change the way I am storing the image data (currently I am just using an array o...

Can't use GCC in OS X Terminal

I have installed the developer tools. I can compile code via Xcode and according to the docs /usr/bin/gcc & /usr/bin/cc should point to /usr/bin/gcc-4.0. Neither the symlinks or gcc-4.0 exist on my system (Snow Leopard). All I wish to do is compile some C on the terminal! I'm amazed by how complicated this task is. The command GCC is uns...

C stdlib .h's on C++ and malloc/realloc

I was really bothered by the inclusion of C stdlib functions on the global namespace and ended up writing things like ::snprintf or ::errno or struct ::stat, etc, to differentiate from some of my own functions in the enclosing namespace where those c stdlib functions were used. Then I discovered that there is a way to declare every C st...

gcc/g++ option to place all object files into separate directory

I am wondering why gcc/g++ doesn't have an option to place the generated object files into a specified directory. For example: mkdir builddir mkdir builddir/objdir cd srcdir gcc -c file1.c file2.c file3.c **--outdir=**../builddir/objdir I know that it's possible to achive this with separate -o options given to the compiler, e.g.: g...

gcc/g++: error when compiling large file

Hi, I have a auto-generated C++ source file, around 40 MB in size. It largely consists of push_back commands for some vectors and string constants that shall be pushed. When I try to compile this file, g++ exits and says that it couldn't reserve enough virtual memory (around 3 GB). Googling this problem, I found that using the command ...

What is the proper way of including linux kernel config?

I'm porting an old version of a software that is partly a linux kernel module to EL5, after doing the relevant hacks, the horrible GNU autotools mess that is used to compile the thing (no, it does not compile the kernel module via kbuild :( ) I keep getting lots of warnings 'Including config.h is deprecated' - I am told by google search...

Segfault on C++ Plugin Library with Duplicate Symbols

Hi, I have a cross platform C++ application that is broken into several shared libraries and loads additional functionality from plugin shared libraries. The plugin libraries are supposed to be self contained and function by themselves, without knowledge of or dependency on the calling application. One of the plugins contains copied...

GCC options to enforce Ansi C standard check?

What gcc options shall I use to enforce ANSI C (C99) warnings/errors? gcc (GCC) 3.4.2 (mingw-special) I'm using: gcc -pedantic -ansi -std=c99 is this correct? ...