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,cef1e23795181e0c X-Google-Attributes: gid103376,public From: robert_dewar@my-dejanews.com Subject: Re: Alternate to Unchecked_Conversion - Portable? Date: 1999/02/25 Message-ID: <7b3glh$ml6$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 448277734 References: <36d05e39.0@news.pacifier.com> <36d2638e.6427631@nntp.concentric.net> <7avpi0$jke$1@nnrp1.dejanews.com> <36d3ba85.713118@nntp.concentric.net> <7b2l6s$vu3$1@nnrp1.dejanews.com> <36d50d18.695962@nntp.concentric.net> X-Http-Proxy: 1.0 x2.dejanews.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Feb 25 12:45:39 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-02-25T00:00:00+00:00 List-Id: In article <36d50d18.695962@nntp.concentric.net>, cjrgreen@concentric.net (Christopher Green) wrote: > Such compilers (there are a few still in use) are, for > reasons like this, virtually useless for the sort of > programming in which address > clauses,Unchecked_Conversion, or equivalence > between C pointer types and Ada access types is > important. No, not at all. They may be virtually useless for careless programmers who do not distinguish between erroneous constructs and those that may theoretically be non-portable but are in practice portable. We have four kinds of programming constructs explicitly and implicitly mentioned here: 1) Using address clauses to achieve erroneous overlays as defined by RM83 2) Using address clauses in a legitimate manner 3) Using Unchecked conversion in general 4) Using Unchecked conversion to convert between Ada access types and C pointers Now of these 4, ONLY 1) is erroneous in Ada 83, and a competent Ada 83 programmer understands what is and what is not erroneous, and avoids erroneous constructs. The rest are not erroneous. In fact the word erroneous appears in the section on UC only to remind you that the resulting value must be valid. Uses of 2) 3) 4) are possibly implementation dependent, and a compiler can theoretically sabotage you by being unreasonable, but here the principle that Chris states is valid. A sensible programmer using these constructs in a reasonable manner using sensible compilers will not run into trouble. But to casually lump erroneous constructs in with implementation constructs is definitely sloppy, and we have seen numerous instances of people having trouble porting Ada 83 code to Ada 95 compilers because of injudicious programmers writing erroneous code that just happened to work. A mantra that should be central to every programmer's view of the universe is: "just because it works does not mean it is right" A lot of programmers violate this because they don't know enough to avoid violations. In this particular case, the use of overlays to achieve the effect of unchecked conversion is almost always a bad programming choice, and leads you into unnecessary implementation dependencies, even in Ada 95 where it is no longer explicitly erroneous. It is almost always better to use unchecked conversion of pointers (making sure OF COURSE that you do not try to use pointers to unconstrained arrays in this context!) -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own