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,ab3fadb7cac7363c 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!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 09 Jun 2011 13:25:58 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Address arithmetic alternatives References: <57e75a35-058c-4172-9a3d-e11e7c5f7697@l2g2000prg.googlegroups.com> <70bda46e-e016-42e8-a0bb-7003ec1488ec@r33g2000prh.googlegroups.com> <6355779b-dab3-4f78-a6f7-78f395426332@v8g2000yqb.googlegroups.com> <5bf3d787-c0b0-45c7-841f-0f08c93a3655@e26g2000vbz.googlegroups.com> In-Reply-To: <5bf3d787-c0b0-45c7-841f-0f08c93a3655@e26g2000vbz.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4df0adc6$0$6629$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 09 Jun 2011 13:25:58 CEST NNTP-Posting-Host: f07efe32.newsspool2.arcor-online.net X-Trace: DXC=;1l`_Th9@2S1`E>oC;JXEZA9EHlD;3YcR4Fo<]lROoRQ8kFZLh>_cHTX3j]2Wj9B?M]cOV X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:20687 Date: 2011-06-09T13:25:58+02:00 List-Id: On 09.06.11 12:40, milouz wrote: > >> More correctly, you *think* you need to play with address arithmetic. You may be >> right, but address arithmetic is needed extremely rarely in Ada. Ada has >> alternatives to most address arithmetic in C. > > You're probably right. But what are those alternatives ? I'd think array indexing (including ptrdiff_t stuff) is a prominent example: while (*s++) { ... } for K in S'Range loop ... end loop; Another is a C functions that reads two pointer, one a start pointer and the other an offset pointer. typedef ... t; t* foo(const t* source, t* offset) { ... In Ada, giving some more information about pointed to array and the pointers via index ranges: type T is ...; type Indexing is range 0 .. Some_Maximum; subtype Position is Indexing range 16#100# .. 16#1FF#; subtype Distance is indexing range 0 .. Position'Last - Position'First; type Array_of_T is array ( Position range <> ) of T; function foo (Source : Array_of_T; Offset: Distance) return Distance; (This doesn't mean that in C one couldn't write s[d], d++ or that in Ada one couldn't use pointers with array components. In fact, Ada.Containers features cursors. There is just much expressive information in typed, constrained index values. Depending on how much type information there is at compile time, the compiler will reject a program if it can thus detect a bounds violation (value not in type).)