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,c9d5fc258548b22a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!212.27.60.9.MISMATCH!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 08 Feb 2011 13:20:25 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How do I write directly to a memory address? References: <67063a5b-f588-45ea-bf22-ca4ba0196ee6@l11g2000yqb.googlegroups.com> <8r86vgFc3uU1@mid.individual.net> <19fh1chm74f9.11cws0j5bckze.dlg@40tude.net> <4d4ff70e$0$6886$9b4e6d93@newsspool2.arcor-online.net> <737a6396-72bd-4a1e-8895-7d50f287960e@d28g2000yqc.googlegroups.com> <4d5008a5$0$6879$9b4e6d93@newsspool2.arcor-online.net> <4d5031fe$0$6765$9b4e6d93@newsspool3.arcor-online.net> <1f229967-d3cf-42b6-8087-c97ee08652f3@i40g2000yqh.googlegroups.com> <4d5116d1$0$7657$9b4e6d93@newsspool1.arcor-online.net> <7c91bcbb-60f5-4630-b05d-1c36c85b7bb1@s11g2000yqh.googlegroups.com> <4d511c9d$0$7658$9b4e6d93@newsspool1.arcor-online.net> <36f322c1-5dc4-427a-9a55-18ea4930f977@e21g2000yqe.googlegroups.com> In-Reply-To: <36f322c1-5dc4-427a-9a55-18ea4930f977@e21g2000yqe.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4d513509$0$6972$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 08 Feb 2011 13:20:25 CET NNTP-Posting-Host: 58295791.newsspool4.arcor-online.net X-Trace: DXC=bTnkIQ=^2WFX36K@\WTHGJ4IUKJLh>_cHTX3jMCC1dBbfYfjI X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:17956 Date: 2011-02-08T13:20:25+01:00 List-Id: On 08.02.11 11:43, Ludovic Brenta wrote: > Georg Bauhaus wrote on comp.lang.ada: >> On 2/8/11 11:16 AM, Ludovic Brenta wrote: >>>> Strict contracts in subprogram profiles. Ha! >> >>>> void foo2(int jump) >>>> /* make sure jump % 2 == 0! */ >>>> { >>>> ... >>>> } > procedure Foo2 (Jump : in Natural) is > begin > if Jump <= Natural'Last / 2 then > Baz (2 * Jump); > else > declare > Half_Jump : constant Natural := Jump / 2; > Remainder : constant Natural := Jump mod 2; > begin > Baz (2 * Half_Hump); > Baz (2 * Half_Jump); > if Remainder /= 0 then > Baz (2 * Remainder); > end if; > end; > end if; > end Foo2; > > And that's assuming Long_Long_Integer is not wide enough for the > calculations. There is lots of assuming here. The original "contract" read void foo2(int jump) /* make sure jump % 2 == 0! */ { ... } (And int includes negative values.) The idea could have been that the least significant bit is not set. Or the idea could have been different. The point is, neither language provides the means of expressing the idea using types. Not yet. The knee jerk reaction of the Ada programmer is to invent a different problem and its solution and show off. It's counterproductive. So, more specifically, define an integer subtype T whose values do not include the values of the static constants A, B, and C, assuming that each of A, B, and C will be members of a proper subrange of T'Range. Make sure that membership in T can be checked at compile time. Do the same for run-time values A, B, and C. What I'd like to point out is that we need a better utility function. A function that properly measures program quality. I imagine that type checking quality vs the type system's flexibility of the respective languages form one variable of the utility function.