How to prevent a function from being optimized

c, c++, gcc

Solution

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

Problem

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?

Original source