I've seen in many places that people often use the option -fomit-frame-pointer
when compiling C / C++ code and I wonder, is the use of that option safe? What is it used for?
Thank you very much, best regards.
I've seen in many places that people often use the option -fomit-frame-pointer
when compiling C / C++ code and I wonder, is the use of that option safe? What is it used for?
Thank you very much, best regards.
So long as your code does not rely on undefined behavior, then it's perfectly safe. It may cause undefined behavior bugs to show up though.
The option is safe but makes debugging harder. Normally, the C compiler outputs code which stores in a conventional register (ebp
on x86) a pointer to the stack frame for the function. Debuggers use that to print out local variable contents and other such information. The -fomit-frame-pointer
flag instructs gcc not to bother with that register. In some situations, this can yield a slight performance increase, mostly due to reduced code footprint (that's better for cache) and to the extra available register (especially on x86 in 32-bit mode, which is notoriously starved on registers).