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:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  2000

COMP-FORTRAN-90 2000

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Real Fortran guru test

From:

Peter Shenkin <[log in to unmask]>

Reply-To:

Peter Shenkin <[log in to unmask]>

Date:

Wed, 10 May 2000 17:57:55 -0400 (EDT)

Content-Type:

TEXT/PLAIN

Parts/Attachments:

Parts/Attachments

TEXT/PLAIN (117 lines)

Hi, Toon,

To answer your question, yes, I think you are missing a few things. :-)

Suppose the original order of the links was 1->2->3 and that you wanted 
to insert a new link after 2, giving 1->2->4->3.

With pointers, you'd do the following.  

	Set 4's NEXT to 2's NEXT
	Set 2's NEXT to 4. 

With allocatable NEXT components, note first that in F9x, only an array 
can be allocatable;  a scalar cannot.  I don't know if this changes for 
f2k, but let's suppose it does.

With allocatables, it's not even obvious what the semantics of
recursive derived-type component membership is, if indeed it is 
allowed.   For example, if we were to set up 1->2->3, allocating 
1's next, then 2's, what would copying 1 to a new link (as in 
"link_new = link1") do?

It would seem that 1 actually contains all of 2, rather than just
a pointer to 2; and that similarly 2 contains all of 3.  So a 
copy of link1 might have to copy all of link2 and link3's
contents, too.  I'm not sure how f2k handles this, but let's
suppose there's a rule that says that on assignment, allocatable
components aren't copied, and these components in the new copy 
have unallocated status.

Then, to do the insertion of link 4, I think you'd have to do the 
following:

	copy the entire chain starting with the NEXT of link2
	 to temporary storage.
	allocate the NEXT of link 2 to the new storage (link 4)
	allocate link 4's NEXT, and it's NEXT, etc. -- enough
	 time to hold the chain stored in the first step
	copy the chain stored in the first step to this newly 
	 allocated storage
	deallocate the chain stored in the first step.

Some of this could be simplified by giving the NEXT
components the TARGET attribute and using POINTERs to hold
the temporary storage, but after all, the whole purpose
of ALLOCATABLE derived-type components is to avoid both these 
things.

Bottom line is that POINTERs are better than ALLOCATABLEs
for linked lists and the like.

Even so, if you want to avoid POINTERs, they aren't completely 
necessary; INTEGERs could be used.  One would maintain a flat 
array of links and use the NEXT component of a link to store 
the index to the next link in the chain.  

With pointers or integers, the advantage is copying some small
reference (pointer or integer) rather than entire link contents, 
or (as appears necessary with ALLOCATABLEs) whole chains of link
contents.

	-P.
         
On Wed, 10 May 2000, Toon Moene wrote:

> Richard Maine wrote:
> > 
> > Toon Moene writes:
> >  > > 1. When you _really_ want a pointer, e.g. for a linked-list.
> >  >
> >  > > 2. When you want an allocatable component of a derived type.
> > 
> >  > I'm coming a bit late in this conversation (been attending a workshop at
> >  > the UK Met. Office the last few days) - but isn't (1) just a specific
> >  > example of (2) ?
> > 
> > Not at all.  Indeed almost the opposite.  In (1) you really want a
> > pointer because it needs to point to something else, as in a linked
> > list.
> 
> Huh? - Perhaps I do not understand "linked lists" ? :-)
> 
> TYPE LINKEDLIST
>    TYPE (LINKEDLIST), ALLOCATABLE :: NEXT
>    TYPE CONTENT
>    blah ... blah ... blah
>    END TYPE CONTENT
> END TYPE LINKEDLIST
> 
> ....
> 
> TYPE(LINKEDLIST) THEHEAD
> 
> ....
> 
> ! Start linked list
> 
> ALLOCATE(THEHEAD % NEXT, bla-dee-blah, STAT=ILOVEYOU)
> 
> I must be missing something ...
> 
> -- 
> Toon Moene - mailto:[log in to unmask] - phoneto: +31 346 214290
> Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
> GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
> GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
> 

--
** Whether the playing field is level depends on the coordinate system. ***
********* Peter S. Shenkin; Schrodinger, Inc.; (201)433-2014 x111 *********
*********** [log in to unmask]; http://www.schrodinger.com ***********



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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