This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: single to double conversion


On Wed, Sep 27, 2006 at 11:38:04AM -0500, Brian Barnes wrote:
> On Wed, 27 Sep 2006, Tobias Burnus wrote:
> 
> Yes, that is exactly the problem, and it was easily fixed by making the
> precision in the function match the precision of the calling subroutine.
> 
> However, in g77, the real*4 of the function was 'detected' and
> auto-promoted to real*8 in the subroutine.  There was loss of precision,
> but that was not important to us.  The g77 compiler seemed to have no
> problem at all in knowing that the precision of the subroutine and
> function differed, and handling the difference gracefully.
> 
> gfortran, on the other hand, gives errant results for the real*8 variable,
> and there is no possible warning by the compiler.  This comes back to my
> original question:  if g77 handles this correctly, why does gfortan fail?

You need to define "correctly".  gfortran is doing exactly what you 
told it to do.  gfortran should not look at the code and decide that
the programmer really meant to do something else.

> Can the behaviour of gfortran be changed?

No, that would be a regression.  It is the responsibility of the
programmer to fix the bugs in his code.

As you found, you can use the -fdefault-real-8 option (or whatever
it is) to achieve your goal.  

>  If it is intentional behaviour,
> can code like this, __which will never work__, be caught with a warning?

Get ftnchek.  It is an excellent tool for finding bugs.

troutmask:kargl[207] ftnchek a.f

FTNCHEK Version 3.3 November 2004

File a.f:

Warning in module A in file a.f: Variables set but never used:
    X set at line 3 file a.f

 0 syntax errors detected in file a.f
 1 warning issued in file a.f

Warning: Subprogram RAN_U invoked inconsistently
    Defined in module RAN_U line 5 file a.f as type real
    Invoked in module A line 3 file a.f as type real*8


-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]