comp.lang.ada
 help / color / mirror / Atom feed
From: Ted Dennison <dennison@telepath.com>
Subject: Re: Ada Queue
Date: 2000/04/07
Date: 2000-04-07T00:00:00+00:00	[thread overview]
Message-ID: <8ckqbi$llg$1@nnrp1.deja.com> (raw)
In-Reply-To: 38ed0123@news.hamilton.edu

In article <38ed0123@news.hamilton.edu>,
  "Joseph T." <thisthat7@hotmail.com> wrote:
>
> Let me ask you this...how come then, did the author of this page ( a
> CS professor) choose the same method shown here:
>
> http://www.cm.cf.ac.uk/Dave/C/node11.html
>
> I think that the Ada replicates the method in C used by this
> professor. Does his code suffer from the same things you mentioned?

For those who don't want to bother surfing there, the relevent source
is:

listelement * AddItem (listelement * listpointer, int data) {

    listelement * lp = listpointer;

    if (listpointer != NULL) {
        while (listpointer -> link != NULL)
            listpointer = listpointer -> link;
        listpointer -> link = (struct listelement  *) malloc (sizeof
(listelement));
        listpointer = listpointer -> link;
        listpointer -> link = NULL;
        listpointer -> dataitem = data;
        return lp;
    }
    else {
        listpointer = (struct listelement  *) malloc (sizeof
(listelement));
        listpointer -> link = NULL;
        listpointer -> dataitem = data;
        return listpointer;
    }
}
(please forgive the funky formatting Deja may force on this)

To answer your question: No this is not the same. The equivalent of his
interface in (your) Ada would be:

function Enqueue (Q : in Queue; E : in Element_Type) return Queue is


He *does* still suffer from the extraneious assignment problem, but it
happens on the outside of the Enqueue call as an artifact of his
decision to use a function return for the new Queue value. Yours put it
on the inside, where its arguably just as wasteful, but a lot more
obvious.

The reasons I think he probably did it this way are:

1, C has no "in out" parameters like Ada. In order to emulate them, he'd
have to have used something like "listelement ** listpointer", a
construction that is both ugly and error-prone.

2. C automaticly gives you a function return, which subtly encourages
developers to find some use for it.

In other words, I think his interface has more to do with the failings
of C than anything else. This is a very good example of why its not
generally best to do wrote translations of C code into Ada.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




  parent reply	other threads:[~2000-04-07  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-06  0:00 Ada Queue Joseph T.
2000-04-06  0:00 ` Ted Dennison
2000-04-06  0:00   ` Joseph T
2000-04-06  0:00     ` Robert Dewar
2000-04-06  0:00       ` Ted Dennison
2000-04-06  0:00       ` Joseph T
2000-04-07  0:00         ` Ole-Hjalmar Kristensen
2000-04-06  0:00     ` Ted Dennison
2000-04-06  0:00       ` Joseph T.
2000-04-07  0:00         ` Ole-Hjalmar Kristensen
2000-04-07  0:00           ` Joseph T
2000-04-07  0:00             ` Ted Dennison
2000-04-07  0:00         ` Ted Dennison [this message]
2000-04-07  0:00           ` Hyman Rosen
2000-04-06  0:00     ` tmoran
2000-04-08  0:00       ` tmoran
2000-04-07  0:00 ` Simon Wright
2000-04-09  0:00   ` Robert Dewar
2000-04-07  0:00 ` MaggieJohn
2000-04-07  0:00   ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox