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,29f8f005ed05b2f6 X-Google-Attributes: gid103376,public From: WishList@2600.com (Technobabble) Subject: Re: Thanks Tucker, It works !!! Date: 1998/09/20 Message-ID: #1/1 X-Deja-AN: 393021111 References: <6u2nk6$p4d$1@nnrp1.dejanews.com> Organization: WannaBeACracker NNTP-Posting-Date: Sun, 20 Sep 1998 09:35:13 MDT Newsgroups: comp.lang.ada Date: 1998-09-20T00:00:00+00:00 List-Id: > Yes, well of course this code works, but you should never > write code you don't fully understand! agreed, I'm working on learning it. > It is of course > trivial to remove the gratuitous use of access in a program > like this, and it is almost certainly the case that in the > "real" code, there is also no good reason for using access. > > No, of course this code will not work in Ada 83. One could > perhaps push it into working by using > 'Address and unchecked conversion and hoping that the > compiler will be friendly enough for this to work (there > is no guarantee that it would). Consider a user of the package test_pkg: with test_pkg; proceder User_proc is My_This is new This; begin xyz5_array : aliased This.xyz_array := (1..5 => 0); This.XYZ(1) := xyz5_array'ACCESS; the user then calls my_range: This.my_range (My_This); end User_proc; Ok, since I really missed the point about stack versus heap allocation, as far as I know the user will be using static heap allocation and my own poor communticatin of this problem has led me to the issue of aliased pointers. So from the previous post could I do this? : with test_pkg; proceder User_proc is My_This is new This; xyz5_array is new This.xyz_array'((1..5 => 0)); begin This.XYZ(1) := This.xyz_array'((1..5 => 0)); the user then calls my_range: my_range (My_This); end User_proc; I'll compile it and see. I started this way but had problems understanding the issue of assignment of an access type to unconstrained versus the constrained side of the equation, hence the late night psycho bable, bad syntax, and massive confusion. Thanks for your patience. Maybe I don't need the aliased approach at all. > THe introduction of aliased and the access attribute into > Ada 95 was always a controversial one. This kind of low > level pointer messing was excluded from Ada 83 for very > good reasons. It was introduced in Ada 95 for very narrow > uses. Historically, the argument that overcame many people's > great uneasiness with this feature was the need for creating > statically initialized data structures containing pointers. > > Once there, the feature also has some other legitimate uses, > but I think it tends to cause more trouble than it is worth. > For example, people are often getting into trouble trying to > model external C routines by using access parameters instead > of pointer parameters. This is almost wrong because of the > (perfectly reasonable if you have the right view of things) > viewpoint that an access parameter should never be null. smart. Thanks for the info, I'll save this letter. > Access parameters the use of 'Access also appear in the case > of function arguments to get around the (extraordinarily > idiotic) rule that functions cannot take in/out parameters. > Here is a case where the language design is simply flawed, > and so people have to get around it (try coding up the > random number packages IN THE RM sometime in Ada!) > > The huge disadvantage of adding a feature like this to the > language is precisely the kind of bad code quoted here. This > code can perfectly well be written without using access (and > the rewrite is a trivial excercise). The appeal to legacy > code is very dubious, seeing as you couldn't do this in > properly written Ada 83 anyway, and if you are dealing with > junk Ada 83 code using unchecked conversion, then it might > as well be converted unchanged. Great explaination! The legacy code is a C/Ada bus driver, I'm converting everything to Ada95 (they told me that they'd get me into an Ada95 training class...soon I hope). > Still the feature is there. If you want to use it, you should > most certainly understand what you are doing. I'd prefer not to use it and to simplify my code fragment along the lines given above if I can do it of course. > The example is a Patriot missile to shoot down a fly. One trusts > there's a reason for this complexity in the actual app. That's really funny. The design was originally done by a pointer crazed C coder. Thanks for the excellent resopnse !!! Richmond