From: Yves Bailly <kafka.fr@laposte.net>
Subject: "User-Defined Assignment" question
Date: Sat, 12 Aug 2006 10:05:57 +0200
Date: 2006-08-12T10:06:22+02:00 [thread overview]
Message-ID: <44dd8bfe$0$17855$626a54ce@news.free.fr> (raw)
Hello all,
Here's a behaviour that sounds strange to me. After carefully reading
the ARM (7.6), I'm not sure if it's legal or not.
Here's a package spec:
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
with Ada.Finalization; use Ada.Finalization;
with System.Storage_Elements; use System.Storage_Elements;
package Pkg is
type T is new Controlled with
record
self: Integer_Address;
id : Natural;
end record;
overriding
procedure Initialize(tt: in out T);
overriding
procedure Adjust(tt: in out T);
overriding
procedure Finalize(tt: in out T);
end Pkg;
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
Here's the body:
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
with Ada.Text_IO; use Ada.Text_IO;
package body Pkg is
overriding
procedure Initialize(tt: in out T) is
begin
tt.self := To_Integer(tt.id'Address);
Put_Line("Initialize " &
Integer_Address'Image(tt.self));
end Initialize;
overriding
procedure Adjust(tt: in out T) is
begin
tt.self := To_Integer(tt.id'Address);
Put_Line("Adjust " &
Integer_Address'Image(tt.self));
end Adjust;
overriding
procedure Finalize(tt: in out T) is
begin
tt.self := To_Integer(tt.id'Address);
Put_Line("Finalize " &
Integer_Address'Image(tt.self));
end Finalize;
end Pkg;
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
So basically, each procedure prints a message showing which instance of
Pkg.T it is given.
Now a small test program:
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
with Ada.Text_IO; use Ada.Text_IO;
with Pkg;
procedure Test is
function Func return Pkg.T is
dummy: Pkg.T;
begin
Put_Line(" Func");
return dummy;
end Func;
tt_1: Pkg.T;
begin
Put_Line("----- START");
tt_1 := Func;
Put_Line("----- END");
end Test;
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
And finally the output:
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
Initialize 3218775648
----- START
Initialize 3218775520
Func
Adjust 134660136
Finalize 3218775520
Finalize 3218775648
Adjust 3218775648
Finalize 134660136
----- END
Finalize 3218775648
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
What seems strange to me is that there is an "Adjust" and a "Finalize"
call on an object which has never been "Initialize"d... look at the
instance identified by 134660136. I guess is some temporary anonymous
object. If I understand well ARM 7.6, the clause 7.6-23/2 seems to tell
that omitting the Initialize call is *not* permitted...
What do you think?
This has been tested using GNAT 2006.
Best regards,
--
(o< | Yves Bailly : http://kafka-fr.net | -o)
//\ | Linux Dijon : http://www.coagul.org | //\
\_/ | | \_/`
next reply other threads:[~2006-08-12 8:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-12 8:05 Yves Bailly [this message]
2006-08-12 12:20 ` "User-Defined Assignment" question Björn Persson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox