- After we created a program and debugged it properly, we normally want it to compile into an efficient code, and the resulting file to be as small as possible.
- The compiler can help us by optimizing the code, either for speed (to run faster), or for space (to occupy a smaller space), or some combination of the two. The basic way to create an optimized program would be like this:
$gcc -O code1.c -o code1
The "-O" flag tells the compiler to optimize the code. This also means the compilation will take longer, as the compiler tries to apply various optimization algorithms to the code.
- This optimization is supposed to be conservative, in that it ensures us the code will still perform the same functionality as it did when compiled without optimization.
- Usually can define an optimization level by adding a number to the "-O" flag. The higher the number - the better optimized the resulting program will be, and the slower the compiler will complete the compilation.
Cem Ozdogan
2011-02-14