comp.lang.ada
 help / color / mirror / Atom feed
From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Record aggregates assignments and the black-box and else
Date: Fri, 07 May 2010 23:23:35 +0200
Date: 2010-05-07T23:23:35+02:00	[thread overview]
Message-ID: <op.vcctpljtxmjfy8@garhos> (raw)

Hi Ada novellers,


I've just had a quick check at the RM, to review what is the exact meaning  
of the black-box in aggregates assignment which are not initialization. I  
was to check if the black-box in this context (all but initialization),  
stands for the actual value or the default value defined in the record's  
full view declaration.

Well, it seems this always stands for the default value, not for the  
actually assigned value of the corresponding members.

[ARM 2005 4.3.1(19.1/2)]
> For a record_component_association with <>, if the component_declaration
> has a default_expression, that default_expression defines the value for
> the associated component(s); otherwise, the associated component(s) are
> initialized by default as for a stand-alone object of the component
> subtype (see 3.3.1).

I did not test on any compiler, as I wanted an answer from the standard's  
point of view.

So the following

    type Record_Type is record
       A : Natural := 1;
       B : Natural := 2;
    end record;

    ...

    R : Record_Type;

    ...

    R.A := 3;

    ...

    R := (A => <>, B => 5)

is expected to result in Record_Type'(A => 1, B => 5);

Now let's come to the reason why I was checking about this.

What I like with the aggregates assignments, is that the compiler will  
shout to wake you up as soon as you forget to think about the value of a  
member (particularly relevant if ever some members are added, this avoid  
you the bad story of out-of-date text sections).

But what about the efficiency of this construct when it is to be used on a  
record which has some members already fixed and which should not change ?

As said above, I like the aggregate assignment as a conscientious  
assignment where you assert you've though about each members in turn and  
none was sadly forgotten (a taste of safety).

If I do :

    R := (A => R.A, B => 5);

what is the most likely expected impact on the executable code efficiency,  
providing this kind of construct oftenly appears in multiple places of the  
source ? (the record type is obviously private and just accessed in the  
implementation).

Do you think most compilers will use the presence of an R's self component  
as an hint for some kind of optimization when applicable ?

-- 
No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just  
not lucky



             reply	other threads:[~2010-05-07 21:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-07 21:23 Yannick Duchêne (Hibou57) [this message]
2010-05-09  0:25 ` Record aggregates assignments and the black-box and else Randy Brukardt
2010-05-10 15:20 ` Adam Beneschan
2010-05-10 19:03   ` Yannick Duchêne (Hibou57)
replies disabled

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