comp.lang.ada
 help / color / mirror / Atom feed
From: Bob Duff <bobduff@theworld.com>
Subject: Re: storage error: stack overflow
Date: Wed, 19 Aug 2015 16:47:55 -0400
Date: 2015-08-19T16:47:55-04:00	[thread overview]
Message-ID: <87k2srf1j8.fsf@theworld.com> (raw)
In-Reply-To: mqvekn$hai$3@dont-email.me

"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> 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

  parent reply	other threads:[~2015-08-19 20:47 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11 21:53 storage error: stack overflow hreba
2015-08-11 22:19 ` Jeffrey R. Carter
2015-08-12 15:01   ` hreba
2015-08-12 16:00     ` AdaMagica
2015-08-12 17:51     ` Jeffrey R. Carter
2015-08-13  2:17       ` hreba
2015-08-12  8:27 ` briot.emmanuel
2015-08-13  1:34   ` hreba
2015-08-13  2:53     ` Jeffrey R. Carter
2015-08-13  7:05     ` Simon Wright
2015-08-14 13:53       ` hreba
2015-08-14 16:01         ` Simon Wright
2015-08-14 17:00         ` Simon Wright
2015-08-13  7:19     ` Simon Wright
2015-08-14 13:20       ` hreba
2015-08-12 10:31 ` Markus Schöpflin
2015-08-13  1:36   ` hreba
2015-08-12 10:57 ` Simon Wright
2015-08-13  0:55   ` hreba
2015-08-13  6:58     ` Simon Wright
2015-08-18  2:16 ` hreba
2015-08-18  5:49   ` Jeffrey R. Carter
2015-08-18  7:24   ` Egil H H
2015-08-18 12:23     ` hreba
2015-08-18 12:37       ` Jacob Sparre Andersen
2015-08-18 14:02         ` hreba
2015-08-18 14:11           ` Dmitry A. Kazakov
2015-08-18 14:16           ` Jeffrey R. Carter
2015-08-18 20:56             ` Randy Brukardt
2015-08-19  1:48             ` hreba
2015-08-19  5:10               ` Jeffrey R. Carter
2015-08-19  8:44               ` Georg Bauhaus
2015-08-19 11:56                 ` hreba
2015-08-19 20:53               ` Bob Duff
2015-08-18 14:15       ` Egil H H
2015-08-19 13:07         ` hreba
2015-08-18 14:16       ` Jeffrey R. Carter
2015-08-19 13:12         ` hreba
2015-08-19 20:47         ` Bob Duff [this message]
2015-08-19 21:47           ` Jeffrey R. Carter
2015-08-20  7:18             ` Dmitry A. Kazakov
2015-08-20 20:48           ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox