I've seen in many places that people o开发者_如何学编程ften 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.
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).
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.
精彩评论