From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Seemingly wierd conversion for in out parameter
Date: 1998/02/26
Date: 1998-02-26T00:00:00+00:00 [thread overview]
Message-ID: <34F5B4D9.6F10@gsfc.nasa.gov> (raw)
In-Reply-To: 34F58B0B.6345@informatik.uni-stuttgart.de
Bernd Holzmueller wrote:
> If no Ada rule is violated in the program presented by Corey Minyard,
> they should perhaps be reconsidered as the following, slightly extended
> program shows:
>
> with Text_IO; use Text_IO;
> with Ada.Tags; use Ada.Tags;
>
> ------------------------------------------------------------------------
> procedure Tester is
>
> type Base is abstract tagged null record;
> type Base_Class is access all Base'Class;
>
> type Der1 is new Base with record X: Integer; end record;
> type Der1_Class is access all Der1'Class;
>
> type Der2 is new Base with record Y: Float; end record;
> type Der2_Class is access all Der2'Class;
>
> procedure Process (Var : in out Base_Class) is
> begin
> Var := new Der2'(Y => 3.45);
> end Process;
>
> V1 : Der1_Class := new Der1;
> -- This will be a compile error.
> -- U1 : Der1_Class := new Der2;
>
> begin
>
> Put_Line("Base tag = " & Expanded_Name(Base'Tag));
> Put_Line("Der1 tag = " & Expanded_Name(Der1'Tag));
> Put_Line("Der2 tag = " & Expanded_Name(Der2'Tag));
>
> Put_Line("V1 tag = " & Expanded_Name(V1'Tag));
>
> V1.X := 6;
>
> Process(Base_Class(V1));
>
> Put_Line("V1 tag = " & Expanded_Name(V1'Tag));
>
> Text_Io.Put_Line("V1.X = " & Integer'IMAGE(V1.X));
>
> end Tester;
>
> This program outputs
>
> Base tag = TESTER.BASE
> Der1 tag = TESTER.DER1
> Der2 tag = TESTER.DER2
> V1 tag = TESTER.DER1
> V1 tag = TESTER.DER2
> V1.X = 1079823565
>
> and the last line of the output is a typical output of an uninitialized
> variable
> which is rather strange for a program that has all objects properly
> initialized!
Running this with ObjectAda 7.1 on Windows 95, we get Constraint_Error
at the call " Process(Base_Class(V1)); ", which is expected since we are
attempting to store a pointer to Der2 in a variable of type access Der1.
GNAT 3.10p on Windows 95 does not raise Constraint_Error here, so I
suspect it has a bug. What compiler are you using? please submit a bug
report!
--
- Stephe
next prev parent reply other threads:[~1998-02-26 0:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-02-20 0:00 Seemingly wierd conversion for in out parameter Corey Minyard
1998-02-23 0:00 ` Albert K. Lee
1998-02-23 0:00 ` Corey Minyard
1998-02-25 0:00 ` Nick Roberts
1998-02-26 0:00 ` Bernd Holzmueller
1998-02-26 0:00 ` Stephen Leake [this message]
1998-02-26 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox