C++ switches -O2; -static; -lm ...

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
blowguy
New poster
Posts: 9
Joined: Sat Apr 15, 2006 6:07 pm

C++ switches -O2; -static; -lm ...

Post by blowguy »

Ok it would be very nice if someone would introduce us with c++ flags(-O2 -static -lm ...) Or atleast pass a link, because in google it is really hard to find any useful info abot because google is not able to find minus.

I know when -O2 flag is in use, my program is twice faster, but why?

And how to add switches in c++ source code, not in compiler command line!
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

http://www.google.com/search?q=man+gcc
And how to add switches in c++ source code, not in compiler command line!
Well, you can't. A (very limited) substitution is #pragma directives.
because in google it is really hard to find any useful info abot because google is not able to find minus.
rotfl, minus tells google to exclude the word after the minus from the search ;) ;) ;)
e.g. 'apple -banana' should return pages containing 'apple', but not containing 'banana'.
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

You can try enclosing the term in quotes, like "-O2", for example.
blowguy
New poster
Posts: 9
Joined: Sat Apr 15, 2006 6:07 pm

Post by blowguy »

mf wrote:http://www.google.com/search?q=man+gcc
And how to add switches in c++ source code, not in compiler command line!
Well, you can't. A (very limited) substitution is #pragma directives.
because in google it is really hard to find any useful info abot because google is not able to find minus.
rotfl, minus tells google to exclude the word after the minus from the search ;) ;) ;)
e.g. 'apple -banana' should return pages containing 'apple', but not containing 'banana'.
Thanks a lot... Those keywords really helped me!
Is there any way i can include swicth -O2 in source???

I mean something like "#pragma -O2"
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

Is there any way i can include swicth -O2 in source???
I don't think it's possible with gcc.

I've heard that on some compilers you can control optimizations in this way:

Code: Select all

#pragma optimization_level X
BUT: gcc does not support it.
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

The best way to use predefined option for all source code, (I don't recommand this) is use some system variable/ or writing a generic Make file.
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof »

Moha wrote:The best way to use predefined option for all source code, (I don't recommand this) is use some system variable/ or writing a generic Make file.
While your answer is technically correct, I assume that the intended question here was "Can I do something to force the UVa compiler to optimize my code?"

And there, the answer is "No." and your suggestions don't help.
blowguy
New poster
Posts: 9
Joined: Sat Apr 15, 2006 6:07 pm

Post by blowguy »

misof wrote:
Moha wrote:The best way to use predefined option for all source code, (I don't recommand this) is use some system variable/ or writing a generic Make file.
While your answer is technically correct, I assume that the intended question here was "Can I do something to force the UVa compiler to optimize my code?"

And there, the answer is "No." and your suggestions don't help.
No You are wrong. I don`t need to optimize my code for uva... I believe that on-line judge automatically do that for me.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

blowguy wrote:I believe that on-line judge automatically do that for me.
Well, I don't know exact gcc switches used by UVa,
But definately, optimization is OFF!
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

From what I understand they compile only with -lm switch.
Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha »

I know UVA doesn't add any optimization option for compiling.
Sometimes adding optimazation to code result in a bad code.(ie. in class constructors it may cause a bad shallow copy!) but it dependes on your!
blowguy
New poster
Posts: 9
Joined: Sat Apr 15, 2006 6:07 pm

Post by blowguy »

Post Reply

Return to “C++”