views:

113

answers:

1

I have a project for which optimization has been set to "-Os" for all files via gcc command line flags. However, I want to disable optimization for some methods in one of the source files. To accomplish that, I am trying to specify the optimization attribute for those methods. However, gcc says that it is ignoring optimize attribute during build. Does any one know what the problem is?

class C 
{
public:
    int __attribute__((optimize("-O0"))) foo();
    .
    .
 };

I am using gcc version 4.4.3.

A: 

Drop the -. It is not required (or probably not expected).

leppie
Tried it. But that does not affect the outcome.
Rajorshi
Normally I would just use the pragma directive, but in the source, not the header.
leppie
It is ignoring `#pragma GCC optimize 0` as well.
Rajorshi
@Rajorshi: But that is not the right syntax...
leppie
@Rajorshi: You need `#pragma GCC optimize ("O0")`
leppie
See http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html
leppie
Hmm. I think GCC accepts the former as well. Anyway, I tried the following but it did not work either: #pragma GCC push_options #pragma GCC optimize ("O0") . . . #pragma GCC pop_options
Rajorshi
It seems gcc is ignoring the `push_options` and `pop_options` directives as well. So there must be something else wrong with it as it looks like it is ignoring all `pragma` directives and not just the optimization ones.
Rajorshi
it looks like `__attribute__((optimize("0")))` should work, if I'm reading the documentation correctly
Hasturkun
No it doesn't. Is there any way to turn all `#pragma` and `__attribute__` directives off from the commandline? I am wondering if someone has done something like that in the project settings.
Rajorshi
@Rajorshi: Unfortunately not, but you could wrap them in some ifdef perhaps.
leppie