The easiest way: put the function in your own compilation unit, compile this flag without optimization flags.
Recent versions of gcc (4.4+, I think) have an attribute to control optimization for each function, use
__attribute__((optimize(0)))
for disable optimization function
source
share