RM 7.6.11? 
Author Message
 RM 7.6.11?

Hi,

   i have a derived a type A from Ada.Finalization.Controlled.
I derived a type B from A. When i create an instance of B, only
B is initialized. I have to call Initialize (...) for A
explicitely. I understand the RM 7.6.11 that this should be
done by the runtime system.

Where the fault in my thinking? Maybe a problem with my gnat 3.10
for OS/2?

Thanks for any ideas
                     Haug

with Ada.Finalization;

package Parent is

   type A is new Ada.Finalization.Controlled with
   record
      P : Natural;
   end record;

   procedure Initialize (Object : in out A);
   procedure Adjust     (Object : in out A);
   procedure Finalize   (Object : in out A);

end Parent;

with Ada.Finalization;
with Ada.Text_IO;                      use Ada.Text_IO;

package body Parent is

   procedure Initialize (Object : in out A) is
   begin
      Put_Line ("Init Parent");
      Object.P := 1;
   end Initialize;

   procedure Adjust     (Object : in out A) is
   begin
      null;
   end Adjust;

   procedure Finalize   (Object : in out A) is
   begin
      null;
   end Finalize;

end Parent;

with Ada.Finalization;
with Parent;

package Child is

   type B is new Parent.A with
   record
      C : Natural;
   end record;

   procedure Initialize (Object : in out B);
   procedure Adjust     (Object : in out B);
   procedure Finalize   (Object : in out B);

end Child;

with Ada.Finalization;
with Ada.Text_IO;                      use Ada.Text_IO;

package body Child is

   procedure Initialize (Object : in out B) is
   begin
      Parent.Initialize (Parent.A(Object));
      Put_Line ("Init Child");
      Object.C := 1;
   end Initialize;

   procedure Adjust     (Object : in out B) is
   begin
      null;
   end Adjust;

   procedure Finalize   (Object : in out B) is
   begin
      null;
   end Finalize;

end Child;

with Ada.Text_IO;                      use Ada.Text_IO;

with Parent;
with Child;

procedure Test is
   A_Child : Child.B;
begin
   Put_Line ("Done");
end Test;

--




Fri, 08 Dec 2000 03:00:00 GMT  
 RM 7.6.11?

Quote:

>    i have a derived a type A from Ada.Finalization.Controlled.
> I derived a type B from A. When i create an instance of B, only
> B is initialized.

That is correct behavior.

Quote:
> I have to call Initialize (...) for A explicitely.

Yes, you do.  That is correct behavior.

Quote:
> I understand the RM 7.6.11 that this should be
> done by the runtime system.

Your understanding is incorrect.  The A-part of type B doesn't
automatically get initialized.

What the RM says is that Initialize for the type gets called.
Initialize for type B does get called, and so your compiler is correct.

Quote:
> Where the fault in my thinking? Maybe a problem with my gnat 3.10
> for OS/2?

This is not a compiler bug.

When you derived from A, you replaced A's Init, Final, and Adj with
versions for the derived type B.  If you want to control the A-portion
of type B, then you have to do that yourself.  (By casting to the parent
type, and then explicitly calling its Controlled operations, as you show
in Initialize.)

If you really want the A-part to be Initialize'd automatically, then you
should make that component Controlled, not the entire type.  Something
like

type Controlled_A is
   new Ada.Finalization.Controlled with record
      P : Natural;
   end record;

procedure Init (CA : in out Controlled_A);

proc Final ...

proc Adj ...

type A is
   record
      CA : Controlled_A;
   end record;

When you derive B from A, the A-part of B will take care of its own
Initialization, etc.  If the B-specific part of type B needs
Controlled'ness, then do as A did:

type Controlled_B is
   new Ada.Finalization.Controlled with record
      C : Natural;
   end record;

type B is
   new A with record
      CB : Controlled_B;
   end record;



Fri, 08 Dec 2000 03:00:00 GMT  
 RM 7.6.11?

  > I derived a type B from A. When i create an instance of B, only
  > B is initialized. I have to call Initialize (...) for A
  > explicitely. I understand the RM 7.6.11 that this should be
  > done by the runtime system.

  Mathew Hearne explained why this supposition is incorrect, but he
didn't mention that the way that you actually did it is expected and
intended.  The programmer may or may not want the parent Initialize
action called, since he is explicitly replacing that action.  In
addition, it is not clear where in the sequence of actions on B that
action should take place, so those decisions are left to the
programmer.

   However, there is a different problem with your code which may
indicate a fundamental misunderstanding.  You have no need to override
Adjust and Finalize in the example, so there is no reason to declare
them specifically.  In that case the actions will be implicitly
declared with the expected effect of performing the corresponding
actions for the parent.
--

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



Fri, 08 Dec 2000 03:00:00 GMT  
 RM 7.6.11?

  > I derived a type B from A. When i create an instance of B, only
  > B is initialized. I have to call Initialize (...) for A
  > explicitely. I understand the RM 7.6.11 that this should be
  > done by the runtime system.

  Mathew Hearne explained why this supposition is incorrect, but he
didn't mention that the way that you actually did it is expected and
intended.  The programmer may or may not want the parent Initialize
action called, since he is explicitly replacing that action.  In
addition, it is not clear where in the sequence of actions on B that
action should take place, so those decisions are left to the
programmer.

   However, there is a different problem with your code which may
indicate a fundamental misunderstanding.  You have no need to override
Adjust and Finalize in the example, so there is no reason to declare
them specifically.  If you don't override them the actions will be
implicitly declared with the expected effect of performing the
corresponding actions for the parent.
--

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



Fri, 08 Dec 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. RM/Cobol 85 v.6.5 applications developed with RM/Panels running under W95

2. Problem with RM/COBOL, RM+DB & telnet

3. Where can I find the best tutorial for rm-cobol and rm-cobol that works under solaris

4. RM-Cobol application installation & RM-runtime version 7.0 for windows

5. system("rm") not working

6. Error: Label duplicated, second used: RM

7. LOGO-L> Reseach Machines Logo (RM LOGO)

8. Reseach Machines Logo (RM LOGO)

9. RM/Cobol

10. Looking for a RM/COBOL book/disk set

11. How compatible are RM Cobol and MF Cobol.

12. rm/cobol version 1.* needed

 

 
Powered by phpBB® Forum Software