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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2203a21a136b39cc X-Google-Attributes: gid103376,public From: kst@sd.aonix.com (Keith Thompson) Subject: Re: Fortran's Equivalence Date: 1997/04/01 Message-ID: #1/1 X-Deja-AN: 229843666 Sender: news@thomsoft.com (USENET News Admin @flash) X-Nntp-Posting-Host: pulsar References: <333840D1.7B12@cae.ca> <5hbcdn$i1h@top.mitre.org> Organization: Aonix, San Diego, CA, USA Newsgroups: comp.lang.ada Originator: kst@pulsar Date: 1997-04-01T00:00:00+00:00 List-Id: In dewar@merv.cs.nyu.edu (Robert Dewar) writes: > Actually unchecked conversion can cause copies, which are more easily > avoided with address overlays. > > I can imagine no technical justification for your claim that UC is > safer, let alone infinitely safer, than address overlays. I suspect > this is just a hold over from Ada 83 thinking, with no good technical > justification. If you use Unchecked_Conversion, you know you're getting either a view or a copy of the operand, wherever the compiler happens to have put it at the moment. For an address clause this isn't guaranteed, at least as far as I can tell from my reading of the RM. AARM-13.3(12.b) says: 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. (Yes, I know that AARM annotations are not part of the standard, but I believe this one is good advice.) RM95-13.3(16) says: X'Address should produce a useful result if X is an object that is aliased or of a by-reference type, or is an entity whose Address has been specified. This implies by omission that there is no requirement for X'Address to mean anything for an ordinary object. If you do use address clauses to implement overlays, be sure to declare all overlaid objects aliased -- something that I don't think has been mentioned in this thread. Since paragraph 16 is marked as "recommended level of support", it is mandatory for implementations that (claim to) support Annex C. Finally, RM95-13.3(19) says: If the Address of an object is specified, or it is imported or exported, then the implementation should not perform optimizations based on assumptions of no aliases. Again, this is part of the "recommended level of support", and thus is mandatory if Annex C is supported. However, it's not clear that it applies to objects whose address is queried rather than specified. More concretely, assume the following declarations: Obj_1 : Some_Type; Obj_2 : Some_Other_Type_Of_The_Same_Size_And_Alignment; for Obj_2'Address use Obj_1'Address; (An important point: an overlay can fail badly if the specified address doesn't satisfy the alignment requirements of the object.) If Obj_1 and Obj_2 are not declared aliased, I see no guarantee in the RM that an assignment to Obj_1 will necessarily be reflected in the value of Obj_2. I'd like to think that if all the overlaid objects are declared aliased, everything will work properly, but I can't find a guarantee of this in the RM (which is no indication that it isn't there). The discussion of distinct access paths in RM95-6.2(12) seems nearly relevant, but it applies only to formal parameters. The nearest Ada equivalent of Fortran's "EQUIVALENCE" is an address clause overlay (or possibly Unchecked_Union if your compiler supports this implementation-defined pragma). However, what you should use when porting Fortran code to Ada depends on how it's used in Fortran. If Unchecked_Conversion make more sense, use it. Try asking yourself what the Fortran author would have used if the language provided both EQUIVALENCE and Unchecked_Conversion. -- Keith Thompson (The_Other_Keith) kst@sd.aonix.com <*> TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix 5040 Shoreham Place, San Diego, CA, USA, 92122-5989 "Humor is such a subjective thing." -- Cartagia