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,c6acbb9f2027b8c9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Wed, 05 Oct 2005 18:35:08 -0500 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1128525722.605730.281980@g43g2000cwa.googlegroups.com> <87mzlnomca.fsf@ludovic-brenta.org> Subject: Re: volatile vs aliased Date: Wed, 5 Oct 2005 18:38:52 -0500 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4952.2800 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4952.2800 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-sfwmBSixD3TDfE3J6QLK4RfS558Ucv17cOYT6YsxetRHZ2NyM4gyYgK6+DdioZwmToc6150sZD1MDv6!7GUthP2oRJwEJixaLW7hmZtvy0v1T6A0mATEgWSC38bgxqVvmPoRi4tBEpmOhEY63kjPaNFCZtoj X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:5430 Date: 2005-10-05T18:38:52-05:00 List-Id: "Ludovic Brenta" wrote in message news:87mzlnomca.fsf@ludovic-brenta.org... ... > In your situation, it seems that you want something like this > (which, incidentally, I use very often): > > type T is ...; > > procedure Read_Variable (At_Address : in System.Address; > Into : out T) is > V : aliased T; > -- suppress default initialisation, I know what I'm doing. > pragma Import (Ada, V); > for V'Address use At_Address; > begin > -- perform my own explicit validation of the variable, perhaps > -- using 'Valid; then, copy into Into: > Into := V; > end Read_Variable; This seems like a good time to mention that I think the explicit use of System.Address in Ada 95 and Ada 200Y code is usually a mistake. Since pragma Convention can be used to ensure that general access types have the appropriate representation, its rare that Address needs to be used for interfacing. (There is only a handful of uses of Address in Claw, for example.) Moreover, when you *do* need to use it, Address_to_Access_Conversions is the best way to convert it, not an overlay (which at best blocks optimizations and at worst won't even work right). type T is ...; procedure Read_Variable (At_Address : in System.Address; Into : out T) is package AAC is new System.Address_to_Access_Conversions (T); V : AAC.Object_Pointer := AAC.To_Pointer (At_Address); begin -- perform my own explicit validation of the pointer's contents, perhaps -- using 'Valid; then, copy into Into: Into := V.all; end Read_Variable; But it is better still to declare an appropriate type and never use Address in the first place: type Pointer_T is access all T; pragma Convention (C, Pointer_T); Address clauses should be restricted to mapping to hardware, IMHO. Randy.