Can a function return from the middle?

Russell Browne russ@amc.com
Mon Apr 9 14:23:00 GMT 2001


Can the compiled version of a C or C++ function ever return
from the middle, or must it always branch to a return sequence
at the end of the function?

For example, consider the function

   static int bar;
   int foo()
   {
      if ( bar )
         return 1;
      return 0;
   }

and the hypothetical assembler output:

    globl foo:
        tst (bar)
        bz  L1
        move #1,d0
        ret			; return from the middle
    L1: clr  d0
        ret


My question is whether gcc would actually output anything like this,
for any processor or at any level of optimization.

If the answer for gcc is NO, can one safely say the answer is NO
for any compiler?

If the answer for gcc is YES, can one safely say that gcc would never
do this for unoptimized code?

Thanks in advance

Russ Browne
Applied MicroSystems



More information about the Gcc mailing list