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,826cd690cb6a7585 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!a10g2000prn.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Address and bit mask Date: Tue, 30 Aug 2011 07:52:27 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8f7b127c-42ba-4b27-afdc-66768553b7bf@a10g2000prn.googlegroups.com> References: <71159ccc-bf20-4fcf-a7f1-3b90629c1ecb@l4g2000vbv.googlegroups.com> <87fwkk0zv7.fsf@ludovic-brenta.org> <2cbc5514-122b-4e8a-9ba0-a699e4f874ec@t5g2000yqj.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1314715947 12763 127.0.0.1 (30 Aug 2011 14:52:27 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 30 Aug 2011 14:52:27 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a10g2000prn.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:21718 Date: 2011-08-30T07:52:27-07:00 List-Id: On Aug 30, 3:34=A0am, Ludovic Brenta wrote: > If the extremely rare case where you really, really must do address > arithmetic, you still don't need bitwise operations on addresses. =A0You > simply use System.Storage_Elements like so: > > function Succ (A : in System.Address) return System.Address is > =A0 =A0Alignment : constant Storage_Offset :=3D 2**3; > =A0 =A0use System.Storage_Elements; > begin > =A0 =A0return (A + Alignment) mod Alignment; > =A0 =A0-- note: "+" and "mod" are in System.Storage_Elements > end Increment; "mod" won't return a System.Address. (Not to mention that you can't end a function Succ with "end Increment", but now I'm just being picky.) Here's a function that rounds A up to the next multiple of Alignment (the result could equal A): function Align_Up (A : in System.Address) return System.Address is Alignment : constant Storage_Offset :=3D 2**3; B : System.Address; use System.Storage_Elements; begin B :=3D A + (Alignment - 1); return B - (B mod Alignment); -- the latter has the effect of zeroing out the low bits of B, like B & ~ALIGN_MASK end Align_Up; -- Adam