* "User-Defined Assignment" question
@ 2006-08-12 8:05 Yves Bailly
2006-08-12 12:20 ` Björn Persson
0 siblings, 1 reply; 2+ messages in thread
From: Yves Bailly @ 2006-08-12 8:05 UTC (permalink / 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 | //\
\_/ | | \_/`
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: "User-Defined Assignment" question
2006-08-12 8:05 "User-Defined Assignment" question Yves Bailly
@ 2006-08-12 12:20 ` Björn Persson
0 siblings, 0 replies; 2+ messages in thread
From: Björn Persson @ 2006-08-12 12:20 UTC (permalink / raw)
Yves Bailly wrote:
> 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...
Per clause 10, Initialize is only called on objects that are initialized
by default, not when they're explicitly initialized. The intermediate
anonymous object is of course initialized with the value of Dummy.
--
Bj�rn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-08-12 12:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-12 8:05 "User-Defined Assignment" question Yves Bailly
2006-08-12 12:20 ` Björn Persson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox