Compiler Optimization

There are two classes of argument flags for controlling optimization, which controls how the compiler generates machine code from your C code, as well as how it rewrites your code to behave more optimally. You can use -O with a number or letter to control the optimization level.

-O0

Do no optimizations.

-O1

Do some optimization (also what’s used if you use -O without a number).

-O2 and -O3

Use yet more aggressive optimization.

-Os

Optimize for size. It does the same optimizations as -O2 but doesn’t do function inlining.

Higher optimization levels can make code unstable as more and more mechanical operations happen to it, so be sure to test when changing levels. Sometimes failures that happen at higher optimization levels ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.