2

Is it possible to write C code so that when it is compiled with

gcc -o foo foo.c

it in fact compiles foo.c with -O2?

I am using gcc 4.4.6.

6
  • 1
    Are you doing the optimization lab from Bryant and O'Hallaron CS:APP? Commented Nov 26, 2013 at 18:43
  • 3
    alias gcc='gcc -O2' Commented Nov 26, 2013 at 18:43
  • @MarcB I need it in the C source itself. Commented Nov 26, 2013 at 18:44
  • @ScottyBauer I am setting work and want to know if they can trick me easily! Commented Nov 26, 2013 at 18:44
  • 4
    wrt "I need it in the C source": you can rebuild gcc to change this behavior. Beware, consumers of @marshall's new compiler! Commented Nov 26, 2013 at 18:49

1 Answer 1

5

recent gcc knows a #pragma GCC optimize pragma (http://gcc.gnu.org/onlinedocs/gcc/Function-Specific-Option-Pragmas.html)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.