Calculating elements addresses from arrays once

Ranjit Mathew
Thu May 20 11:18:00 GMT 2004

Gruik wrote:
>>>My question is : do you think GCC, in this kind of loops, performs a 
>>>little optimisation by saving somewhere the address of my_array[i] ?
>>  Yes, gcc should be doing this kind of optimisation; it's a type of CSE.
>>I'm not sure if -O1 will do it but -O2 certainly ought to.
> What do you mean about -01 and -02 ? i use gcc 3.3.3

He means use the "-O1" or "-O2" optimisation options like:

  gcc -O1 foobar.c


  gcc -O2 foobar.c

As for your original question, if you're a bit familiar
with assembly language you can readily check how well
GCC is able to optimise your code by looking at the
assembly output like so:

  gcc -O2 -S foobar.c

This would create a file named "foobar.s" which by
default uses the AT&T assembler syntax - use "-masm=intel"
(on x86 boxes) to use the more popular Intel assembler
syntax, like so:

  gcc -O2 -S -masm=intel foobar.c

Hope this helps,

Ranjit Mathew          Email: rmathew AT gmail DOT com

Bangalore, INDIA.      Web:

More information about the Gcc mailing list