comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: meaning of "current instance"
Date: 1999/11/11
Date: 1999-11-11T00:00:00+00:00	[thread overview]
Message-ID: <382b4668_4@news1.prserv.net> (raw)
In-Reply-To: wcc7ljo3ld8.fsf@world.std.com

In article <wcc7ljo3ld8.fsf@world.std.com> , Robert A Duff 
<bobduff@world.std.com>  wrote:

> I think you want T to be limited, or else use 'Unchecked_Access.

Yes.  (The example code below is limited.)


>> Object O2 (like O1) has a component I, which is initialized with the
>> "current instance."  But what is the type of the "current instance"
>> here, passed to Init?
>
> Um, I guess it's T, but what difference does it make?  It's *tag* is
> NT'Tag.  Inside Init, we have a value of an anonymous
> access-to-class-wide.  So if Init dispatches, it will dispatch to
> an NT operation.

Function Init does indeed call a dispatching operation.  I was hoping
that the tag of the parameter was NT'Tag, and you have confirmed that
that should be the tag.

However, my compiler (GNAT v3.12p) doesn't dispatch on the NT operation;
it calls the operation for T.


>> procedure Test_P is
>>   OT : T;
>>   ON : NT;
>> begin
>>   Put (OT);
>>   Put (ON);
>> end;
>
> Seems to me it should print:
>
>     I is 0
>     I is 1

That's what I was hoping it would do.  But with my compiler, that's not
what it does.  (The output of my compiler is "I is 0" both times.)


> But I don't see what the type of the expression T'Access has to do with
> it, so perhaps I'm misunderstanding your question.

Perhaps I stated my question incorrectly.

I do not care about the type of the expression T'Access.

I do care about the type of the object designated by the access object
returned by T'Access.

I care because I want to call an operation that dispatches on the tag of
the designated object:

  function Init (O : access T'Class) return Integer is
  begin
    return Do_Init (O);
  end;

where Do_Init is a (private) primitive operation:

  function Do_Init (O : access T) return Integer;


For object O1 (of type T), I want T's Do_Init to be called.

For object O2 (of type NT), I want NT's Do_Init to be called.

My compiler calls T's Do_Init for both O1 and O2.



--
It is impossible to feel great confidence in a negative theory which has
always rested its main support on the weak points of its opponent.

Joseph Needham, "A Mechanistic Criticism of Vitalism"




  reply	other threads:[~1999-11-11  0:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-11  0:00 meaning of "current instance" Matthew Heaney
1999-11-11  0:00 ` Robert A Duff
1999-11-11  0:00   ` Matthew Heaney [this message]
1999-11-11  0:00     ` Tucker Taft
1999-11-15  0:00   ` Tucker Taft
1999-11-15  0:00     ` tmoran
1999-11-15  0:00       ` Tucker Taft
1999-11-11  0:00 ` tmoran
1999-11-11  0:00   ` Matthew Heaney
1999-11-12  0:00     ` tmoran
1999-11-11  0:00       ` Matthew Heaney
1999-11-12  0:00         ` tmoran
1999-11-12  0:00           ` Matthew Heaney
1999-11-12  0:00             ` tmoran
1999-11-12  0:00               ` Matthew Heaney
1999-11-13  0:00             ` Robert A Duff
1999-11-13  0:00           ` Nick Roberts
1999-11-13  0:00             ` Robert A Duff
1999-11-14  0:00               ` tmoran
1999-11-13  0:00                 ` Matthew Heaney
1999-11-15  0:00                   ` John English
1999-11-15  0:00                     ` Matthew Heaney
replies disabled

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