问题
I know that the $ edit descriptor is not in the standard and that using advance="no"
is recommended, but this little example shows that they have a different behaviour (with ifort but not with gfortran) and I don't understand why (it doesn't bother me more than that, but if anyone have an explanation I'm interested!).
program p
use sleep_mod
implicit none
integer :: i
character(len=80) :: mymsg
mymsg = 'H e l l o w o r l d ! W e l c o m e - B i e n v e n u e - W i l l k o m m e n'
!
!- Write the characters of "mymsg" on the same line with a time delay between them:
!
write(*,*)
do i = 1, len_trim(mymsg)
call usleep (onesec/4)
write(*,'(a1,$)') mymsg(i:i) ! ok w/ gfortran, ok w/ ifort
! write(*,'(a1)',advance='no') mymsg(i:i) ! ok w/ gfortran, KO w/ ifort
end do
write(*,'(/)')
end program p
The sleep_mod module is the following:
module sleep_mod
use iso_c_binding
integer(c_int32_t), parameter :: onesec = 100000_c_int32_t
interface ! found in http://computer-programming-forum.com (by Tobias Burnu)
subroutine usleep (useconds) bind(C)
use iso_c_binding
implicit none
integer(c_int32_t), value :: useconds
end subroutine
end interface
end module sleep_mod
With the $ version, whatever is the compilator (ifort or gfortran) the result is as expected: a time delay between each character print. The same result is obtained with the version with advance='no'
compiled with gfortran but not with ifort.
来源:https://stackoverflow.com/questions/50757637/comparing-edit-descriptor-and-advance-no-in-fortran-output