I want to enable optimization in g++ without command line parameter.
I know GCC can do it by writing #pragma GCC optimize (2)
in my code.
But it seems won\'t work i
This appears to be a bug in g++
(Bug 48026, references another related issue.)
As a workaround, you can mark each function with __attribute__((optimize("whatever")))
. Not great.
int main() __attribute__((optimize("-O2")));
int main()
{
long x;
x=11;
x+=12;
x*=13;
x/=14;
return 0;
}
$ g++ -Wall -c t.c
$ objdump -d t.o
t.o: file format elf64-x86-64
Disassembly of section .text.startup:
0000000000000000 :
0: 55 push %rbp
1: 31 c0 xor %eax,%eax
3: 48 89 e5 mov %rsp,%rbp
6: 5d pop %rbp
7: c3 retq