Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Limited ini...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 15 Topic 5621 of 5800
Post > Topic >>

Re: Limited initialization for non-limited types

by "Randy Brukardt" <randy@[EMAIL PROTECTED] > Mar 26, 2008 at 05:13 PM

"Eric Hughes" <eric.eh9@[EMAIL PROTECTED]
> wrote in message
news:b481036a-41ee-4fc5-a0d0-c73cfef60234@[EMAIL PROTECTED]
> Is there any way of getting in-place initialization for non-limited
> objects?  This would be similar to that for limited types as specified
> in ARM05/7.5(8.1/2).

There's no way to require it. And I wouldn't expect that to change -
*requiring* implementations to be able to call a single function with
different return mechanisms seems way over the top. (Of course,
implementations are *allowed* to do that if they like.)

There is a second reason: implementations are allowed to optimize
non-limited controlled types in almost any way that is "correct" (that is,
an initialized object gets finalized). OTOH, limited controlled types are
not allowed to be optimized at all. Even if if the object is never
directly
used.

The net effect is that the operations of non-limited controlled types
cannot
depend on the order that the operations will be called (anywhere), while
limited controlled can always be depended on. Such dependence in
non-limited
controlled is just wrong; it's likely to break if the code is moved to a
different compiler (or even a newer version of the same compiler, as Bob
points out).

> Unfortunately, this is not a hypothetical question.  I'm writing a
> test object used within the unit tests a certain package.  The test
> object is instrumented for white-box testing; it contains a trace
> object as a component.  I want to trace the three events of
> Ada.Finalization.Controlled.  The trace object is associated with the
> variable itself, not with any value that the variable might contain.

I'd probably suggest finding a different approach. (Not that I can think
of
one off-hand.)

....
> 2) Variable-specific record components.  Consider this:
>
>     type X is new Ada.Finalization.Controlled with
>         record
>             -- value components (ordinary)
>         private
>             -- variable components (persistent)
>             T : Trace ;
>         end record ;
>
> The idea is that components in the private section are simply not
> copied under assignment.

Interesting, but sounds messy to implement, because it would complicate
the
"bit-copy" part of the assignment. That's not usually done
component-by-component!

> 3) Anonymous limited types.  I don't see any particular reason why the
> semantics couldn't be worked out for the following declaration:
>
>     B : limited Any_Type := Initial_Value_Function ;
>
> The ARM is littered with references to phrases such as "the limited
> view of a type".  What are the semantic difficulties with this?  For
> single declarations they seem to be modest.  Isn't this almost the
> same as an in-but-not-out parameter to a procedure?

Anonymous types are a cancer as it is, we surely don't need any more of
them. (Besides, they rarely actually work, since it's usually the case
that
you need to write a type conversion or member****p somewhere, and you can't
do that without a name.)

> 4) Derived limited types.  The ARM states (roughly) that a limited
> type must derive from limited types.  But what about a type that is
> explicitly a limited view of a possibly not-limited type?
>
>     type C is overriding limited new Any_Type ;

That's already possible for untagged types - any limited private type can
be
completed by a non-limited type (including a derivation of some other
type).
For tagged types, it would lead to a mess because you could use the
class-wide root type to copy limited extension components. (And if you try
to ban such components, you're going to have to break privacy.)

So, just write:
    package P is
       type C is limited private;
       -- Operations on C.
    private
       type C is new Any_Type;
    end P;

                                     Randy.
 




 15 Posts in Topic:
Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-26 06:26:42 
Re: Limited initialization for non-limited types
Robert A Duff <bobduff  2008-03-26 10:02:46 
Re: Limited initialization for non-limited types
"Dmitry A. Kazakov&q  2008-03-26 16:08:01 
Re: Limited initialization for non-limited types
"Randy Brukardt"  2008-03-26 17:13:14 
Re: Limited initialization for non-limited types
Lucretia <lucretia9@[E  2008-03-26 16:00:15 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-26 17:07:10 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-26 20:25:05 
Re: Limited initialization for non-limited types
"Randy Brukardt"  2008-03-28 01:56:02 
Re: Limited initialization for non-limited types
Martin Krischik <krisc  2008-03-28 12:23:41 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-28 08:25:08 
Re: Limited initialization for non-limited types
"Randy Brukardt"  2008-03-28 16:53:27 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-28 08:47:37 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-03-28 16:37:04 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-04-01 20:00:02 
Re: Limited initialization for non-limited types
Eric Hughes <eric.eh9@  2008-04-01 21:06:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 19:03:39 CDT 2008.