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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5d3a1501d97dab65 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: C to Ada : a piece of code Date: 1996/09/08 Message-ID: <01bb9d61$537fe5e0$2b8371a5@dhoossr.iquest.com>#1/1 X-Deja-AN: 179224917 distribution: world references: <3231732C.2781@virgoa4.in2p3.fr> content-type: text/plain; charset=ISO-8859-1 organization: DBH Enterprises, Inc. mime-version: 1.0 newsgroups: comp.lang.ada Date: 1996-09-08T00:00:00+00:00 List-Id: Jon S Anthony wrote in article ... > In article <3231732C.2781@virgoa4.in2p3.fr> Grave Xavier 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