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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8a34575d5eb275cb X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!v15g2000yqn.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Load an object from a file Date: Fri, 3 Apr 2009 13:22:19 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <49d5fa88$0$2862$ba620e4c@news.skynet.be> <443d72ca-5bbd-46a3-84c6-e8bd984e5b80@k41g2000yqh.googlegroups.com> <49d628f5$0$2865$ba620e4c@news.skynet.be> <49d6346e$0$32681$9b4e6d93@newsspool2.arcor-online.net> NNTP-Posting-Host: 94.108.129.105 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1238790139 31427 127.0.0.1 (3 Apr 2009 20:22:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 3 Apr 2009 20:22:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v15g2000yqn.googlegroups.com; posting-host=94.108.129.105; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.7) Gecko/2009030810 Iceweasel/3.0.7 (Debian-3.0.7-1),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4428 Date: 2009-04-03T13:22:19-07:00 List-Id: Adam Beneschan wrote on comp.lang.ada: > P.S. You may need to be a bit cautious if you define U2 as a modular > type, as Ludovic suggested, and then use it as the base type of an > unconstrained array. =A0If you define > > =A0 =A0 type Some_Array is array (u2 range <>) of u2; > > you might be tempted to write code like this: > > =A0 =A0 procedure Do_Some_Operation (Count : U2) is > =A0 =A0 =A0 =A0Result : Some_Array (0 .. Count - 1); > =A0 =A0 =A0 =A0... > > If you call Do_Some_Operation(0), Result is not going to be an empty > array like you expect, but rather an array too large to fit in your > computer, because 0-1 doesn't return a negative number for modular > types but rather a very large positive number. In the light of Adam's remark, type u2 is mod 2 ** 16; is the exact equivalent of Java's u2, but we now see that Java's u2 does _not_ represent the problem domain accurately; therefore defining u2 in Ada as type u2 is range 0 .. 2 ** 16 - 1; does reflect the problem domain accurately (i.e. in the problem domain, there is no wrap-around semantics) at the expense, perhaps, of exposing bugs in the Java code :) -- Ludovic Brenta.