From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f32236e7e55b02e0 X-Google-Attributes: gid103376,public From: Ted Dennison Subject: Re: Ada Queue Date: 2000/04/07 Message-ID: <8ckqbi$llg$1@nnrp1.deja.com>#1/1 X-Deja-AN: 607898907 References: <38eca724@news.hamilton.edu> <8ciesn$4mt$1@nnrp1.deja.com> <38ecc752@news.hamilton.edu> <8cisft$jtg$1@nnrp1.deja.com> <38ed0123@news.hamilton.edu> X-Http-Proxy: 1.0 x32.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri Apr 07 14:12:13 2000 GMT X-MyDeja-Info: XMYDJUIDtedennison Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.7 [en] (WinNT; I) Date: 2000-04-07T00:00:00+00:00 List-Id: In article <38ed0123@news.hamilton.edu>, "Joseph T." 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.