INTEGER or REAL?

Steve Kargl sgk@troutmask.apl.washington.edu
Sun Aug 22 23:14:00 GMT 2010


On Mon, Aug 23, 2010 at 01:00:28AM +0200, Angelo Graziosi wrote:
> Sorry, but I do not understand why gfortran does not compile this code:
> 
> $ cat dp_test.f90
> program dp_test
>   implicit none
>   integer, parameter :: DP = selected_real_kind(12,60)
>   call foo(0_DP)
> contains
>   subroutine foo(x)
>     real(DP), intent(in) :: x
>     print *, x
>   end subroutine foo
> end program dp_test
> 
> $ gfortran dp_test.f90
> dp_test.f90:4.11:
> 
>   call foo(0_DP)
>            1
> Error: Type mismatch in argument 'x' at (1); passed INTEGER(8) to REAL(8)
> 
> WHY is '0_DP' interpreted as an 'INTEGER(8)' and not as a REAL(DP)?
> 

Because 0_8 is an integer.

The compiler does not determine the type of a constant
actual argument based on the type of a dummy argument.

-- 
Steve



More information about the Fortran mailing list