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-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Address and bit mask Date: Tue, 30 Aug 2011 11:40:21 +0100 Organization: A noiseless patient Spider Message-ID: References: <71159ccc-bf20-4fcf-a7f1-3b90629c1ecb@l4g2000vbv.googlegroups.com> <87fwkk0zv7.fsf@ludovic-brenta.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="5545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YEcAbj8+H2UwpMnSds6zo+OIPLvXBQkA=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:xAwIbfh129bVQry/HCqr4pDfyKE= sha1:REYs+8kILoJNyt8tJD8yyfTk4Xo= Xref: g2news1.google.com comp.lang.ada:20734 Date: 2011-08-30T11:40:21+01:00 List-Id: milouz writes: > Hum... well... I still do not know how to do some simple arithmetic > with address. So, let me give you an example in C : > > p = (char*) (((unsigned long)p + ALIGN_MASK) & ~ALIGN_MASK); > > How do you write that in Ada ? Perhaps you could achieve that by using the Alignment attribute? ------------------------------ with Ada.Text_IO; With System.Storage_Elements; procedure Alignment is type Aligned_Char is new Character; for Aligned_Char'Alignment use 16#1000#; type Character_P is access Character; type Aligned_Char_P is access Aligned_Char; C : constant Character_P := new Character'('c'); A : constant Aligned_Char_P := new Aligned_Char'('a'); package Address_IO is new Ada.Text_IO.Modular_IO (System.Storage_Elements.Integer_Address); begin Ada.Text_IO.Put ("Address of allocated Character:"); Address_IO.Put (System.Storage_Elements.To_Integer (C.all'Address), Base => 16); Ada.Text_IO.New_Line; Ada.Text_IO.Put ("Address of allocated Character:"); Address_IO.Put (System.Storage_Elements.To_Integer (A.all'Address), Base => 16); Ada.Text_IO.New_Line; end Alignment; ------------------------------ gnatmake -gnatwa alignment.adb gcc -c -gnatwa alignment.adb alignment.adb:6:35: warning: suspiciously large alignment specified for "Aligned_Char" gnatbind -x alignment.ali gnatlink alignment.ali ------------------------------ $ ~/tmp/alignment Address of allocated Character: 16#1092008F0# Address of allocated Aligned_Char: 16#7F9164001000# $