From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,679afa9cacbaebd9,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!novia!newsfeed.icl.net!proxad.net!cleanfeed3-a.proxad.net!nnrp11-1.free.fr!not-for-mail Message-Id: <44dd8bfe$0$17855$626a54ce@news.free.fr> From: Yves Bailly Subject: "User-Defined Assignment" question Newsgroups: comp.lang.ada Date: Sat, 12 Aug 2006 10:05:57 +0200 User-Agent: KNode/0.10.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Organization: Guest of ProXad - France NNTP-Posting-Date: 12 Aug 2006 10:06:22 MEST NNTP-Posting-Host: 81.56.171.53 X-Trace: 1155369982 nnrp11-1.free.fr 17855 81.56.171.53:56858 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:6184 Date: 2006-08-12T10:06:22+02:00 List-Id: 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 | //\ \_/ | | \_/`