Is there a way to tell GCC not to optimise a particular piece of code?
gcc, optimization
Solution
GCC has since 4.4. the `#pragma GCC optimize ("whatever")`. I would also recommend to wrap the particular code, that is annotated with this pragma with `#pragma GCC push_options` and `#pragma GCC pop_options`. The first will save the options as they were before your change, the later will restore them afterwards and the rest of the code will compile with the global options.
For details on the whatever string, you should look into the gcc doc, here the most important part of it: `Arguments can either be numbers or strings. Numbers are assumed to be an optimization level. Strings that begin with O are assumed to be an optimization option, while other options are assumed to be used with a -f prefix.`.
That means if you dont want any optimizations on your particular code your whatever should just be "0".
Problem
I am working on a project that relies on compiler optimisations but I need some code not to be optimised by GCC. Is this possible?