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,CP1252 Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 30 Aug 2011 14:35:18 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0) Gecko/20110812 Thunderbird/6.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Address and bit mask References: <71159ccc-bf20-4fcf-a7f1-3b90629c1ecb@l4g2000vbv.googlegroups.com> <87fwkk0zv7.fsf@ludovic-brenta.org> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Message-ID: <4e5cd906$0$7623$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 30 Aug 2011 14:35:19 CEST NNTP-Posting-Host: 9c7f441e.newsspool1.arcor-online.net X-Trace: DXC=RYfIX]PWZWmUoRk[hk2Walic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgbTT2:ZAgWN2anc\616M64>jLh>_cHTX3jmOl@^lX[]Ind X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:20740 Date: 2011-08-30T14:35:19+02:00 List-Id: On 30.08.11 11:14, milouz wrote: > Hum... well... I still do not know how to do some simple arithmetic > with address. As has been said, addresses are addresses of something. The "something" which your pointers will refer to can be addressed, aligned, and laid out very specifically using the attribute functions and packages mentioned. OTOH... > So, let me give you an example in C : > > p = (char*) (((unsigned long)p + ALIGN_MASK) & ~ALIGN_MASK); The only address arithmetic in there is ... I'm not sure, have you got the parentheses right? Assuming this from the Linux kernel source: /* * Round up the ptr to an 8-byte boundary. */ #define ALIGN_MASK 7 static inline void *align_ptr(void *ptr) { return (void *) (((size_t) (ptr + ALIGN_MASK)) & ~ALIGN_MASK); } (Which, incidentally, gives test.c:8:34: warning: pointer of type �void *� used in arithmetic) Assuming your program cannot control alignment using 'Alignment, layout specifications, and offsets etc, as Ludovic has shown. Cannot perform arithmetic on addresses using this function from System.Storage_Elements: function "+"(Left : Address; Right : Storage_Offset) return Address; Also assuming that you want exactly C's pointer arithmetic, copying C's rules, relying on void* casts, and not use Ada facilities for a reason. (Side note: C's pointer arithmetic and alignment are not defining what's in the hardware, storage elements are not defined in C WRT size etc; C refers to hardware and compiler for further reading. That's somewhat less so in Ada.) Then Interfaces.C.Pointers is your friend, for helping with writing C in Ada, including the necessary C pointer arithmetic functions, such as function "+" (Left : in Pointer; Right : in ptrdiff_t) return Pointer; It is also worthwhile searching the compiler docs that state which type corresponds with C's void* on your platform. (System.Address in case of many GNATs.) If the platform allows direct interpretation of the bits of a pointer as an Unsigned_N (no composite pointers, for example), then after Unchecked_Conversion, the bit operations used in align_ptr above would be those of Unsigned_N (with suitable N), named "and" and "not".