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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Bob Duff Newsgroups: comp.lang.ada Subject: Re: storage error: stack overflow Date: Wed, 19 Aug 2015 16:47:55 -0400 Organization: A noiseless patient Spider Message-ID: <87k2srf1j8.fsf@theworld.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="e99bcc0f0b4289ef0350c938adfc1184"; logging-data="28523"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OcZLhJIiz0O4tQGksmIXv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:feT7Hemda0FxrePQZU4FIYsLS14= sha1:KmitAm1QEacI8NZvZQuL4YDQAww= Xref: news.eternal-september.org comp.lang.ada:27510 Date: 2015-08-19T16:47:55-04:00 List-Id: "Jeffrey R. Carter" writes: > On 08/18/2015 05:23 AM, hreba wrote: >> >> I need an access type because in my real program TB is a tagged type and I need >> class-wide variables. > > You do not /need/ access types for this. Avoiding them requires some thought, > but that's what S/W engineers do. I don't think it's fair to say that people who use access types (i.e. pointers) aren't proper "S/W engineers". It's true that Ada doesn't require pointers in many cases where other languages do. But Ada still requires pointers if the class-wide variable needs to change its tag. And pointers are required for recursive data structures. Etc. I think what you and Randy have been saying (or should have been?) is more like: 1. Try to avoid using pointers. 2. When you have to use them, try to encapsulate. 3. When possible, use the encapsulations already provided by the language (i.e. the Ada.Containers). But there are all sorts of reasons why Ada.Containers might not be suitable, so in those cases, you WILL use pointers, preferably encapsulated. But that's different from saying "never use pointers" (or "never use access types"). >> Didn't know about extended return (the Ada 95 book was cheaper -:). But there is >> a problem: the TB in my original program is not only tagged, it is limited too >> (and New_TB is for initialization). So "foo.all:=..." is forbidden. > > If your type is limited then you will have to use an extended return for Ada > > 95. ... I'm not sure what you mean by that. There is no rule that return of a limited type requires extended return. This: return expression; means exactly the same thing as: return Result : T := expression do null; end return; whether T is limited or not. You only need extended return when you want to have a name for the function result (so you can assign into parts of it, for example). And anyway, the example is returning an access value, which is not limited. > ...Does > > return Foo : access TB := > new TB'( (A => TA'(Name => To_Unbounded_String (Name) ) ); > > work? Maybe you were just hoping that the extended return version wouldn't tickle the same compiler bug? That's possible, but unlikely; I didn't try it. Anyway, that could be written: return new TB'( (A => TA'(Name => To_Unbounded_String (Name) ) ); and mean the same thing. - Bob