Two of Eef's bugs, was: Re: gfortran

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Dec 22 17:52:00 GMT 2006


On Fri, Dec 22, 2006 at 04:19:20PM +0100, Tobias Schl?ter wrote:
> 
> Eef relies on the following to work (in his case i<100):
>   integer i
>   character*20 c
>   write (c(1:5),*) i
>   end
> We give a runtime error, because the record is too small to hold the  
> list-formatted output form of i.  Are we right?  Since this is a  
> regression WRT to g77, we should probably fix this in any case.  I  
> will open a PR if people agree.
> 

Eef has a bug in his code.  From Section 10.8.2 of F95,

   "Integer output constants are produced with the effect of
    an Iw edit descriptor."
    ...
   "For numeric output, reasonable processor-dependent values
    of w, d, and e are used for each of the numeric constants
    output."

For portable code, Eef needs to determine the processor-dependent
value for w.   I'll suggest

      integer i,n
      character*20 c
      c = '                    '
      i = 1
      n = range(i) + 3
      write(c(1:n),*) i
      write(*,'(A)') c(1:n)
      end

Why +3?  You need space for the sign and one or more separators.

Alternatively, gfortran could set w to the minimum value necessary
to format i plus a leading separator.
-- 
Steve



More information about the Fortran mailing list