From: Tucker Taft <stt@averstar.com>
Subject: Re: Operator visibility/inheritance for derived private type? (Repost)
Date: 2000/01/28
Date: 2000-01-28T21:24:48+00:00 [thread overview]
Message-ID: <38920920.DB464062@averstar.com> (raw)
In-Reply-To: 38905ACA.B406AA72@praxis-cs.co.uk
Rod Chapman wrote:
>
> Confused of Bath writes:
>
> Imagine I have a package exporting a private type with an
> explicitly redeclared "=" operator - Ada.Task_Identification.Task_ID
> for instance. I want to derive another private type from
> this, exporting only a subset of the operations of the original,
> so I write
>
> with Ada.Task_Identification;
> package Rod.TI is
> type Task_ID is private;
> function Current_Task return Boolean;
> private
> type Task_ID is new Ada.Task_Identification.Task_ID;
> end Rod.TI;
>
> If a user of this package does
>
> A, B : Rod.TI.Task_ID;
> begin
> if A = B then ...
>
> which "=" is called? Do I get some simple comparison of
> A and B or should I get a call of
> Ada.Task_Identification."="?
Semantically, you end up with a "call" on Ada.Task_Identification."=", but
that might of course be a built-in "simple comparison" operation.
It certainly doesn't need to be an out-of-line function call.
> GNAT (3.12a3 on NT) seems to be generating the former,
> but I'm not sure if the language requires the latter,
> and GNAT is simply doing an optimisation. If
> I _definintely_ want the call to Ada.Task_Identification."=",
> so I need to explicitly redeclare my own "=" for
> Rod.TI.Task_ID? Which language rule(s)
> am I missing to explain what going on?
How do you know that GNAT is generating a "simple comparison" but
not a "call" on Task_Identification."=", since they very well might
be one and the same thing?
You could check GNAT by writing your own package, and making your
"=" a user-defined function. In that case, GNAT should generate
an out-of-line call on your function. However, since Ada.Task_Identification
is provided by the GNAT implementators, it seems quite likely that
the "=" on task IDs uses the built-in equality operation, presuming
it does the "right thing." I wouldn't really call this an "optimization,"
but rather just the expected way of doing things.
> Cheers,
> Rod Chapman
> Praxis Critical Systems
--
-Tucker Taft stt@averstar.com http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.) Burlington, MA USA
prev parent reply other threads:[~2000-01-28 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-01-27 0:00 Operator visibility/inheritance for derived private type? (Repost) Rod Chapman
2000-01-28 0:00 ` Tucker Taft [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox