fortran90 - How does automatic typecasting (type conversion) work in Fortran? -


i using gfortran compiler. tell me if gfortran uses other fortran standard while performing automatic typecasting (type conversion).

assignment defined fortran 2008 section 7.2. of note cl. 7.2.1.3 paragraph 8:

for intrinsic assignment statement variable of numeric type, expr may have different numeric type or kind type parameter, in case value of expr converted type , kind type parameter of variable according rules of table 7.9.

table 7.9: numeric conversion , assignment statement

type of variable     value assigned integer              int(expr , kind = kind (variable)) real                 real(expr , kind = kind (variable)) complex              cmplx(expr , kind = kind (variable)) 

this means expression (expr) implicitly converted type , kind of variable being assigned to. character types, derived types , else, please see standard.

also note fortran performs conversions during assignment , initialization not contexts procedure calls. example, consider procedure:

subroutine sub1(a)  implicit none  integer ::       print *,   end subroutine 

this procedure has dummy argument of type integer. cannot, example, this:

call sub1(1.d0) 

because results in mismatch of type between actual , dummy arguments.

you can, however, this:

integer :: a = 1.d0     !implicitly interpreted as: = int(1.d0, kind=kind(a)) call sub1(a) 

because implicit conversion defined assignment.


the documented extension standard implicit type conversion in gfortran (5.1.0) between logical , integer types during assignment.

see: https://gcc.gnu.org/onlinedocs/gcc-5.1.0/gfortran/implicitly-convert-logical-and-integer-values.html#implicitly-convert-logical-and-integer-values

  • logical .true. converted integer 1
  • logical .false. converted integer 0
  • integer 0 converted .false.
  • any other integer converted .true.

do note if can without legacy extensions don't use them. using them means program not standard fortran , compiler free reject being incorrect. extensions meant allow legacy code compile modern compilers , not use in new code.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -