optimization differences between cmd line and code declarations
Apparently optimzations work differently when putting the -O<xxx> in the cmd line and into the code. This is version 4.7.4. (the current version supported by my tool vendor iSystem). Copy-and-paste the following code into a standalone C file and include it in any project with no -O option in the command line:
/******
//#pragma GCC optimize ("Ofast")
unsigned long Fibonacci(unsigned long p_Arg)
//unsigned long __attribute__ ((optimize(
{
switch(p_Arg)
{
case 0:
case 1: return p_Arg;
default: return Fibonacci(
};
}
/******
In the second step, uncomment either the pragma or __attribute___ lines and rebuild. The resulting code will (expectedly) be different. In the third step, re-start from the original code (leaving all the commented lines commented) but add the option -Ofast to the command line. The code will be different from step 2, implying that -Ofast means different things when invoked from the command line and within the code.
Is this behavior by design and/or documented anywhere? Apologies if this should have been addressed before, I scanned all QAs regarding optimizations and couldn't find any reference.
Thanks!
Edit Feb 19, 2016: It appears that the optimization is done when -Ofast is within the source file and not the cmd line is the same performed as when -O2 is selected.
Edit Feb. 28, 2016: Reopened due to its still applicability. This is pretty severe in my opinion and possibly trivial to solve, in any case easy to reproduce, why are there no takers? Thanks!
Question information
- Language:
- English Edit question
- Status:
- Expired
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: