fortran66のブログ

fortran について書きます。

"Modern Fortran Explained" の付録 oo.f90 が動かない件の続報

http://fortran.lang.comp.groups.com.ru/144652-Re_Errata_list_for_Modern_Fortran_Explained
Host is not delegated


https://groups.google.com/forum/#!topic/comp.lang.fortran/aRz3HMpblTs

Object-oriented list example in "Modern Fortran Explained" does not work


要するに Subroutine DELETE が間違っておるから要修正。


以下丸々引用

On Thursday, July 24, 2014 10:25:02 AM UTC+2, michael...@compuserve.com wrote:
> Le mardi 22 juillet 2014 22:34:10 UTC+2, FortranFan a écrit :
>
> > On Wednesday, September 18, 2013 4:16:11 AM UTC-4, michael...@compuserve.com wrote: > Am Dienstag, 16. April 2013 10:39:00 UTC+2 schrieb michael....@compuserve.com: > > > Since "Modern Fortran Explained" was published two years ago a number of errors have been detetected, sometimes by contributors to this newsgroup (to whom our thanks). An errata list has now been prepared, and is available at ftp://ftp.numerical.rl.ac.uk/pub/MRandC/edits.pdf. Regards, Mike Metcalf > > > > Please note that this file has again been updated: > > > > ftp://ftp.numerical.rl.ac.uk/pub/MRandC/edits.pdf > > > > Regards, > > > > Mike Metcalf Mike, Re: the extended OO example in Appendix E of this book, can you please confirm there have been no further edits to the code since your note dated 5th of June, 2013?
>
>
>
> Dear FortranFan,
>
> Unfortunately, I'm away from base for three weeks so will have to try to get a reply to you by other means. However, I note that at ftp://ftp.numerical.rl.ac.uk/pub/MRandC/ the most recent version of edits.pdf is 24 March, 2013 and the most recent version of oo.f90 is 30 October, 2014.
>
>
>
> Watch this space.
>
I'm sorry that it has taken so long to reply definitively to your message,
but holidays are now drawing to a close and I hope the following clarifies
the situation. In fact, several corrections to oo.f90 are called for, and
maybe I could ask you to post them too on the intel site.

Firstly, we do not agree with yamajun when he says

> Dummy argument "item" is alias to "list%firstptr"
> (actual argument of SUBROUTINE DELETE_LIST).

They are not aliases - they are pointers with the same target. Also

> This means the line
> "list%firstptr => item%nextptr" is the same as
> "item => item%nextptr".

Again no, as this is just changing the target of list%firstptr.

Unfortunately, there is no explanation of why temp is needed in subroutine
delete. It is because a passed-object dummy argument is not allowed to be a
pointer. However, we assume that item was created by allocation of a
pointer target and want to deallocate it. Hence the use of the pointer
temp that points to it.

But, in fact, it turns out that subroutine delete is anyway wrong, although
it will work on most if not all compilers.
The reason is that you should not be able to
destroy a dummy argument, although the standard contains no such actual
prohibition (something we will follow up). Taking account of all this, the
following changes ensure that it should work in all circumstances. The
downloadable code has been updated at ftp://ftp.numerical.rl.ac.uk/pub/MRandC/oo.f90.


433:-3 Add "delete," after "anyitem,".

434:middle. Change line
procedure, non_overridable :: delete
to
! delete has a pointer argument so cannot be type bound

437: a third of the way down. Change lines
class(anyitem), target :: item
class(anyitem), pointer :: temp
temp => item
call remove(item)
deallocate (temp)
to
! We want to deallocate the dummy argument, so it must be a pointer.
! It follows that the procedure cannot be a type-bound procedure.
class(anyitem), pointer :: item
call remove(item)
deallocate (item)

440:middle. Change line
call p%delete
to
call delete(p)


Thank you for drawing this to our attention.

Mike Metcalf