comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: C to Ada : a piece of code
Date: 1996/09/08
Date: 1996-09-08T00:00:00+00:00	[thread overview]
Message-ID: <01bb9d61$537fe5e0$2b8371a5@dhoossr.iquest.com> (raw)
In-Reply-To: JSA.96Sep7205717@alexandria


Jon S Anthony <jsa@alexandria> wrote in article
<JSA.96Sep7205717@alexandria>...
> In article <3231732C.2781@virgoa4.in2p3.fr> Grave Xavier
<xavier@virgoa4.in2p3.fr> writes:
> 
>     type Vec_Array_Type is array ( Positive range <> ) of Long_Float;
>     Size : Natural;
> ...
>     Integer_Text_IO.Get(Size);
>     declare
>         Vec : Vec_Array_Type(1..Size); -- No malloc, no linked list.
>     begin
>         for I in Vec'Range loop
>             Vec(i) := ....;
>         end loop;
>     end;
> /Jon
Hi Jon,
Two things about your solution are not direct translations, viz.:
    1.  The declare block is not equivalent to calloc or malloc, inasmuch
as the array goes out of scope when exiting the block.  Your declaration
would be equivalent to alloca.  Xavier doesn't say whether he intends to
pass this pointer off to somewhere that's out of scope, in which case the
malloc or new is required.
    2.  Xavier specified a 0-based index for the array, whereas your is
1-based.  I know that C gives no choice in the matter, but Ada does, and
many times the 0-based index is more mathematically convenient, depending
on the application.

Refer to my previous post for a suggested solution.

In my original post, I had intended to ask Xavier why he went to the
expense of calloc, when malloc would be cheaper, and he was going to assign
all values in his loop.
-- 
David C. Hoos, Sr.,
http://www.dbhwww.com
http://www.ada95.com






  reply	other threads:[~1996-09-08  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-07  0:00 C to Ada : a piece of code Grave Xavier
1996-09-07  0:00 ` Robert A Duff
1996-09-07  0:00 ` David C. Hoos, Sr.
1996-09-08  0:00 ` Jon S Anthony
1996-09-08  0:00   ` David C. Hoos, Sr. [this message]
1996-09-09  0:00     ` nasser
1996-09-09  0:00   ` Jon S Anthony
1996-09-09  0:00     ` David C. Hoos, Sr.
1996-09-09  0:00       ` John G. Volan
1996-09-09  0:00       ` Robert Dewar
1996-09-10  0:00         ` Geert Bosch
1996-09-11  0:00           ` Robert Dewar
1996-09-11  0:00             ` Jonas Nygren
1996-09-13  0:00             ` Geert Bosch
1996-09-14  0:00               ` Robert Dewar
1996-09-11  0:00           ` Robert Dewar
1996-09-13  0:00             ` Geert Bosch
1996-09-14  0:00               ` Robert Dewar
1996-09-10  0:00 ` Jon S Anthony
replies disabled

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