Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!tektronix!uunet!ficc!peter
From: peter@ficc.uu.net (Peter da Silva)
Newsgroups: comp.lang.fortran
Subject: Re: Data types _without_ pointers
Message-ID: <1601@ficc.uu.net>
Date: 24 Sep 88 14:44:21 GMT
References: <1580@ficc.uu.net> <4096@lanl.gov>
Organization: SCADA
Lines: 74

In article <4096@lanl.gov>, jlg@lanl.gov (Jim Giles) writes:
> From article <1580@ficc.uu.net>, by peter@ficc.uu.net (Peter da Silva):
> > 	struct {
> > 		struct list *prev, *next;
> > 		data;
> > 	} *p, *q;
> > 	...
> > 	q->next = p;
> > 	p->prev->next = q;
> > 	q->prev = p->prev;
> > 	p->prev = q;

>       type dlink
>          integer data
>          dlink :: next, prev       !recursive data declaration
>       end type dlink

>       dlink :: p, q
>       ...
>       q%next = p                   !Fortran 8x uses % for the structure ref
>       p%prev%next = q              !I know!  I don't like % either
>       q%prev = p%prev
>       p%prev = q

> No pointers!  Only variables of type 'dlink'.

So, how do you differentiate between copying pointers and copying structures?
In 'C' I can say:

	extern struct doubly_linked_list empty_list;	/* initialised to
							   empty in runtime
							   initialisation,
							   say */
	struct doubly_linked_list header;

	header = empty_list;	/* initialise header by copying data in */

Now in Fortranoid:

	dlink :: emptylist
	common /initlist/ emptylist	! initialised to an empty list
					! in runtime initialistion.
	dlink :: header

	header = emptylist	! Is this a pointer copy or a structure copy?

Say what you mean and mean what you say.

Before you ask if I ever use such things, the answer is 'yes'. In fact,
I frequently copy list elements. Here is an example from a program I'm
using on a real-time operating system (Browser on AmigaDOS):

struct MessagePort *messageport;	/* messageport contains a
					   doubly linked list */
struct Message *msg, copymsg;	/* message is a list element */

	msg = GetMsg(messageport);
	if(I'm going to be using this message for a while) {
		copymsg = *msg;	/* copies contents of msg */
		ReplyMsg(msg);	/* releases it for reuse */
		msg = copymsg;	/* keep the code tidy */
	}

	use msg, without caring if it's local or not.

	if(msg != copymsg)
		ReplyMsg(msg);

How would you do this without pointers, and without confusing the hell
out of the syntax of your linked lists? And without making a subroutine
call (in-line copies can be much faster... efficiency remember).
-- 
Peter da Silva  `-_-'  Ferranti International Controls Corporation.
"Have you hugged  U  your wolf today?"            peter@ficc.uu.net