JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Monospaced Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2003

COMP-FORTRAN-90 2003

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: obscure fortran features

From:

Richard Maine <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Thu, 14 Aug 2003 10:55:26 -0700

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (89 lines)

Drew McCormack writes:

 > If you have another term that can convey to general programmers the
 > model used by Fortran, I'll be happy to use it.

I don't know of a good single term (other than "argument associated",
which isn't going to help anyone except the guru who has already
studied the standard in depth; it doesn't really describe the
ralationship - just gives a name to it). I just say that changing the
dummy argument also causes the actual argument to change. In my
experience, "general programmers" haven't even heard the term
"pass-by-reference" unless they have been "corrupted" by C, so you'll
have to explain what you mean anyway. (And programmers who picked up
the term from C are particularly likely to write buggy code if you
tell them that pass-by-reference is the model).

 > On a related issue, I seem to recall that in Fortran 90 the following
 > code was not guaranteed to work,...
   [code elided]

The only thing I see wrong with the code is irrelevant to your
question. Procedures with pointer dummy arguments need explicit
interfaces. I don't see one in your sample, but I really doubt that
is what you were talking about. Other than that, the code looks
perfectly fine to me (in f90 and everything afterwards).

Only two things that I can think you might be referring to

1. Things can get complicated if you point to a dummy argument.
    I don't even recall all the details of that. I'd not only have
    to look them up, I'd have to study very carefully and reread
    some interpretations on the subtle points. (And I'm not
    going to have time to do that). Other people on the list
    are probably more up on the question than I am. Yes, this
    gets into subtle issues of argument passing. But this
    is *NOT* what your sample code is doing.

2. If the target is an unsaved local variable, then you have
    problems. This isn't fundamentally any different from the
    issue of unaved local variables in f77 (and earlier, though
    things get murky prior to f77, where there wasn't a SAVE
    statement). Unsaved local variables become undefined when
    you exit a procedure. Has nothing to do with argument passing
    at all.

You might possibly be misreading the standard and thinking that
your code is a case of item 2 above. It isn't. If you are mistaking
it for item 2, then you are missing a fundamental thing about
pointers - a ponter and its target are 2 distinct things, even
if sometimes it seems unobvious. When you have a pointer B and do

  allocate(b)

that doesn't actually allocate B itself. (Yes, I know it reads
as though it does, but it doesn't.) What this does is 2 things.

1. The statement allocates an anonymous target. I call it anonymous
   because it doesn't have a name. It is *NOT* actually B; it is a
   separate thing all of it's own and has existance independent of B.
   This distinction is important.

2. The statement then makes B point to this target. There is now a
   relationship between B and the target (B is pointer associated
   with the target), but they are still separate things.

If you then do

  A -> B

this does *NOT* make A point to B. It makes A point to the target
of B. The difference is crucial. B is an unsaved local variable
and becomes undefined on exit from the subroutine. However, the
anonymous target is not a local variable and does not become
undefined. It maintains it's independent existance when the
subroutine returns.

 > In other words, it is valid to pass a pointer to a subroutine, and set
 > the pointer in the subroutine?

Yes. If it weren't allowed, then there wouldn't be much point
(so to speak) in pointer dummy arguments at all. There are certainly
particular thnigs you can do that are invalid, but nothing so
broad and fundamental as that.

--
Richard Maine | Good judgment comes from experience;
[log in to unmask] | experience comes from bad judgment.
                             | -- Mark Twain

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

December 2023
February 2023
November 2022
September 2022
February 2022
January 2022
June 2021
November 2020
September 2020
June 2020
May 2020
April 2020
December 2019
October 2019
September 2019
March 2019
February 2019
January 2019
November 2018
October 2018
September 2018
August 2018
July 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
December 2015
November 2015
October 2015
September 2015
August 2015
June 2015
April 2015
March 2015
January 2015
December 2014
November 2014
October 2014
August 2014
July 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager