www.delorie.com/gnu/docs/gcc/g77_691.html   search  
 
Buy the book!


Using and Porting GNU Fortran

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.6.2 Transforming DO WHILE

`DO WHILE(expr)' must be implemented so that temporaries needed to evaluate `expr' are generated just for the test, each time.

Consider how `DO WHILE (A//B .NE. 'END'); ...; END DO' is transformed:

 
for (;;)
  {
    int temp0;

    {
      char temp1[large];

      libg77_catenate (temp1, a, b);
      temp0 = libg77_ne (temp1, 'END');
    }

    if (! temp0)
      break;

    ...
  }

In this case, it seems like a time/space tradeoff between allocating and deallocating `temp1' for each iteration and allocating it just once for the entire loop.

However, if `temp1' is allocated just once for the entire loop, it could be the wrong size for subsequent iterations of that loop in cases like `DO WHILE (A(I:J)//B .NE. 'END')', because the body of the loop might modify `I' or `J'.

So, the above implementation is used, though a more optimal one can be used in specific circumstances.


  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003