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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,610e53a911ec64b3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-25 16:47:24 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!news.sprintlink.net!crash!telesoft!kst From: kst@thomsoft.com (Keith Thompson) Subject: Re: Importing C Structures X-Nntp-Posting-Host: pulsar Message-ID: Originator: kst@pulsar Sender: news@thomsoft.com (USENET News Admin @flash) Organization: Thomson Software Products, San Diego, CA, USA References: <3kr4q3$jd9@newsflash.concordia.ca> <3ksg66$h1c@newssvr.cacd.rockwell.com> Date: Sat, 25 Mar 1995 09:57:08 GMT Date: 1995-03-25T09:57:08+00:00 List-Id: In vladimir@speedy.intrepid.com (Vladimir Vukicevic) writes: > There is no such clause in the Ada 95 LRM... the "Erroneous Execution" > section for using a X'Address representation clause (13.3 (13)) states: > > If an Address is specified, it is the programmer's responsibility > to ensure that the address is valid; otherwise, program execution > is erroneous. > > So, it is perfectly valid to use the same 'Address for two objects, as > long as the Address you specify is valid :-) Here's an example of an erroneous use of address clauses in Ada 83: X : Integer; ... Y : Integer; for Y use at X'Address; The reason this is erroneous is that the compiler may not be aware that X and Y are really the same object (X may be declared in a different compilation unit, or the overlaid object might be something more complex than a simple object, say a dynamically indexed array element). The compiler is free to keep the value of X in a register, optimize out dead assignments, etc., so the apparent values of X and Y won't track each other as the user might naively expect. The AARM, if I'm reading it correctly, still gives implementations considerable freedom to treat such constructs as erroneous. Paragraph 13.3(13) says If an Address is specified, it is the programmer's responsibility to ensure that the address is valid; otherwise, program execution is erroneous. What does "valid" mean in this context? See paragraph 12.b in the same subsection: The validity of a given address depends on the run-time model; thus, in order to use Address clauses correctly, one needs intimate knowledge of the run-time model. Caveat hacker. A minor digression: Initialization of objects with address clauses has caused a lot of problems in Ada 83; the language doesn't give permission not to initialize such objects, but if you're trying to map an access or System.Address object to a hardware register you probably don't want it initialized to null. Paragraph 12.c of the AARM says: If the Address of an object is specified, any explicit or implicit initialization takes place as usual, unless a pragma Import is also specified for the object (in which case any necessary initialization is presumably done in the foreign language). (The language specified in the pragma Import can be Ada.) -- Keith Thompson (The_Other_Keith) kst@thomsoft.com (kst@alsys.com still works) TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718 That's Keith Thompson *with* a 'p', Thomson Software Products *without* a 'p'.