tags:

views:

210

answers:

1

I am optimizing the entire code, yet I dont want a certain function from being optimized, say for debugging purposes. Is there a way to do it on gcc 3.4+ compiler?

+10  A: 

Easiest way, place the function in its own compilation unit, compile that one without optimization flags.

Recent gcc versions (4.4+ I think) have an attribute to control optimization per functions, use

__attribute__((optimize(0)))

on the function to disable optimizations

nos
Compilers generally __do not__ gurantee that debug/release version of binaries have the same ABI or padding etc.... Thus it is not safe (in the general case) to assume that this will work (though it may work for your compiler).
Martin York
Do you have an example? I know the microsoft uses a different C runtime for debug executables, but that the cross-module function call and structure alignment interoperability is guaranteed. And gcc generates 100% compatible output in all regimes, as far as I know.Obviously things like structure alignment and ABIs are outside the realm of the language standard, so compilers don't *have* to honor them when generating debug output. But that strikes me as more a pedantic point than a practical one.
Andy Ross