From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp1-2.free.fr!not-for-mail Subject: Re: Record initialisation question Newsgroups: comp.lang.ada References: <5ff9779d$0$24281$426a74cc@news.free.fr> <5ffb311f$0$16185$426a74cc@news.free.fr> <5ffb7135$0$24247$426a74cc@news.free.fr> <5ffc8efd$0$8957$426a74cc@news.free.fr> <60004212$0$13563$426a34cc@news.free.fr> <1064b0e8-2486-42be-a52d-1b3bc0bfd65en@googlegroups.com> From: DrPi <314@drpi.fr> Date: Fri, 15 Jan 2021 08:50:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <1064b0e8-2486-42be-a52d-1b3bc0bfd65en@googlegroups.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Message-ID: <60014950$0$24269$426a74cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 15 Jan 2021 08:50:40 CET NNTP-Posting-Host: 82.65.30.55 X-Trace: 1610697040 news-1.free.fr 24269 82.65.30.55:55531 X-Complaints-To: abuse@proxad.net Xref: reader02.eternal-september.org comp.lang.ada:61136 List-Id: Le 14/01/2021 à 17:53, Shark8 a écrit : > Another option, which IIUC should work within the constraints, being Pure: > > With > Ada.Unchecked_Conversion, > System; > > Package Example with Pure is > > Type Address_Stub is null record > with Size => Standard'Address_Size, Warnings => Off; > Function Convert(Input : System.Address) return Address_Stub; > > Type Stub is null record with Size => 8, Warnings => Off; > Type Static_Record is record > Reserved_1 : Stub; > X, Y : Integer; > Self : Address_Stub; > end record; > > Generic > Location : System.Address; > Package Based is > > Function Create( X, Y : Integer ) return Static_Record; > Private > Function Create( X, Y : Integer ) return Static_Record is > (Self => Convert( Location ), Reserved_1 => (null record), > X => X, Y => Y > ); > End Based; > > > Private > Use System, Ada; > > Function Address_Conversion is new Unchecked_Conversion( > Source => Address, > Target => Address_Stub > ); > Function Convert(Input : System.Address) return Address_Stub > renames Address_Conversion; > End Example; > > -- Usage should be something like: > Object_Address : Constant System.Address := (<>); > Package Object_Basis is new Example.Based( Object_Address ); > Object : Example.Static_Record := Object_Basis.Create( Params => <> ); > For Object'Address use Object'Address; > > Sorry but I haven't done much in the way of microcontrolers, so this is best-guess on my part. The restrictions of Pure *should* comport with the restrictions you have though, again IIUC. > Unchecked_Conversion is not compatible with no elaboration code.