comp.lang.ada
 help / color / mirror / Atom feed
* RE: Question on controlled types
@ 2003-10-01 20:03 Beard, Frank Randolph CIV
  2003-10-02 18:45 ` Robert I. Eachus
  0 siblings, 1 reply; 20+ messages in thread
From: Beard, Frank Randolph CIV @ 2003-10-01 20:03 UTC (permalink / raw)
  To: Alex Xela, comp.lang.ada

Well, not exactly nothing.  It initializes J.  In this case, A gets set
to 0 (zero).  The version that causes PROGRAM_ERROR happens because the
Initialize method is called before it has been elaborated.

IIRC, basically the differences are:

--+ Initialize without calling the Initialize procedure.
J : Instrum.Instrum_Type := (Ada.Finalization.Controlled with A=>0);

--+ Call the Initialize procedure.
J : Instrum.Instrum_Type;

--+ Call Finalize for J, copy X, then call Adjust for J.
J := X;

Frank


-----Original Message-----
From: Alex Xela [mailto:xela2@free.fr]

On the following code, what should happen during J variable elaboration?

 - Nothing

 - A call to Adjust.

I tried to find the answer in RM95 but in vain.

My tests on several compilers (and my feeling) were suggesting  : nothing!





--CODE :
begin ----------------------------------------------------------------------
------------------

with Ada.Finalization;

package Instrum is

    type Instrum_Type is new Ada.Finalization.Controlled with

    record

        A : Integer;

    end record;

    procedure Finalize  (O : in out Instrum_Type);

    procedure Adjust  (O : in out Instrum_Type);

    procedure Initialize  (O : in out Instrum_Type);

    J : Instrum.Instrum_Type := ( Ada.Finalization.Controlled with
A=>0);--nothing?

    --J : Instrum.Instrum_Type; --raised PROGRAM_ERROR : access before
elaboration

end Instrum;

--CODE :
end ------------------------------------------------------------------------
------------------



^ permalink raw reply	[flat|nested] 20+ messages in thread
* Question on Controlled types
@ 2009-05-30 11:41 Olivier Scalbert
  2009-05-30 13:27 ` Dmitry A. Kazakov
  2009-05-30 13:30 ` christoph.grein
  0 siblings, 2 replies; 20+ messages in thread
From: Olivier Scalbert @ 2009-05-30 11:41 UTC (permalink / raw)


Hello,

I am learning controlled types features and I do not understand the 
following thing.

With this code:
-------------------------------------
     Spec
-------------------------------------
with audio; use audio;
with Ada.Finalization; use Ada.Finalization;

package audio.effect is

     type Delay_Line is limited private;

     function Make_Delay_Line (Duration: Duration_Type) return Delay_Line;

private

     type Delay_Line is new Controlled with record
         Duration: Duration_Type;
     end record;

     overriding procedure Initialize(Object: in out Delay_Line);
     overriding procedure Adjust(Object: in out Delay_Line);
     overriding procedure Finalize(Object: in out Delay_Line);

end audio.effect;

-------------------------------------
     Body
-------------------------------------
with Ada.Text_IO; use Ada.Text_IO;

package body audio.effect is

     function Make_Delay_Line(Duration: Duration_Type) return Delay_Line is
         D: Delay_Line;
     begin
         Put_Line("Make_Delay_Line");
         return D;
     end Make_Delay_Line;

     procedure Initialize(Object: in out Delay_Line) is
     begin
         Put_Line("Initialize Delay_Line");
     end;

     procedure Adjust(Object: in out Delay_Line) is
     begin
         Put_Line("Adjust Delay_Line");
     end;

     procedure Finalize(Object: in out Delay_Line) is
     begin
         Put_Line("Finalize Delay_Line");
     end;

end audio.effect;

-------------------------------------
     Test
-------------------------------------
with audio.effect; use audio.effect;

procedure test1 is
     Delay1 : Delay_Line := Make_Delay_Line(Duration => 0.1);
begin
     null;
end test1;

-------------------------------------
     Program output
-------------------------------------
Initialize Delay_Line
Make_Delay_Line
Adjust Delay_Line
Finalize Delay_Line
Finalize Delay_Line

I have two "Finalize(s)" for one "Initialize".
Should I call Initialize from Adjust ?

How to have only one Initialize/Finalize ?

Thanks to help me,

Olivier.





^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: Question on controlled types
@ 2003-10-02  8:05 christoph.grein
  0 siblings, 0 replies; 20+ messages in thread
From: christoph.grein @ 2003-10-02  8:05 UTC (permalink / raw)
  To: comp.lang.ada

A more elaborated analysis of what is going on with controlled types/objects can 
be found here:

http://home.t-online.de/home/Christ-Usch.Grein/AdaMagica/Secretive.html



^ permalink raw reply	[flat|nested] 20+ messages in thread
* Question on controlled types
@ 2003-10-01 19:06 Alex Xela
  2003-10-01 23:07 ` Matthew Heaney
  0 siblings, 1 reply; 20+ messages in thread
From: Alex Xela @ 2003-10-01 19:06 UTC (permalink / raw)


On the following code, what should happen during J variable elaboration?

 - Nothing

 - A call to Adjust.

I tried to find the answer in RM95 but in vain.

My tests on several compilers (and my feeling) were suggesting  : nothing!





--CODE :
begin ----------------------------------------------------------------------
------------------

with Ada.Finalization;

package Instrum is

    type Instrum_Type is new Ada.Finalization.Controlled with

    record

        A : Integer;

    end record;

    procedure Finalize  (O : in out Instrum_Type);

    procedure Adjust  (O : in out Instrum_Type);

    procedure Initialize  (O : in out Instrum_Type);

    J : Instrum.Instrum_Type := ( Ada.Finalization.Controlled with
A=>0);--nothing?

    --J : Instrum.Instrum_Type; --raised PROGRAM_ERROR : access before
elaboration

end Instrum;

--CODE :
end ------------------------------------------------------------------------
------------------






^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2009-06-06  1:31 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-01 20:03 Question on controlled types Beard, Frank Randolph CIV
2003-10-02 18:45 ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
2009-05-30 11:41 Question on Controlled types Olivier Scalbert
2009-05-30 13:27 ` Dmitry A. Kazakov
2009-05-30 14:16   ` Olivier Scalbert
2009-05-30 14:48     ` Olivier Scalbert
2009-05-30 15:20       ` Robert A Duff
2009-05-30 15:40         ` Olivier Scalbert
2009-05-30 18:37           ` Robert A Duff
2009-06-04 12:32   ` Hibou57 (Yannick Duchêne)
2009-06-04 14:04     ` Dmitry A. Kazakov
2009-06-04 14:34       ` Hibou57 (Yannick Duchêne)
2009-06-04 15:03         ` Dmitry A. Kazakov
2009-06-04 15:13           ` Hibou57 (Yannick Duchêne)
2009-06-06  1:31       ` Randy Brukardt
2009-05-30 13:30 ` christoph.grein
2003-10-02  8:05 Question on controlled types christoph.grein
2003-10-01 19:06 Alex Xela
2003-10-01 23:07 ` Matthew Heaney
2003-10-02  7:09   ` Alex Xela

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