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 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!news-xxxfer.readnews.com!news-out.readnews.com!s09-02.readnews.com!not-for-mail X-Trace: DXC=7mZE[b14B9Q_P16K_6TlWT[3OhcoN[H0PX44`8^\]>7Z25[I[UfBM:U User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: A bad counterintuitive behaviour of Ada about OO References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <53e1b409$0$32544$862e30e2@ngroups.net> NNTP-Posting-Host: 6ff6c4cb.ngroups.net Xref: news.eternal-september.org comp.lang.ada:21479 Date: 2014-08-06T06:50:17+02:00 List-Id: The program is doing exat what is should. May i sugest you to put the folowing line in all methods. --------------------------------------------------------------------- pragma debug (GNAT.IO.Put_Line (GNAT.Source_Info.Enclosing_Entity & " " & Object.Handle'img)); -------------------------------------------------------------------- And compile with assertions enabled. And reflect on the output. /Per On 05.08.2014 22:09, Victor Porton wrote: > http://freesoft.portonvictor.org/binaries/ada-obj-test.tar.gz > > contains a tiny Ada program which prints 0 despite intuition suggests that > it should print 123, because it just copies (using Adjust) an object holding > 123. > > In this program Handle_Type models some handle provided by an external API, > where 0 is an undefined handle. Base_Object is a tagged record which holds a > handle inside itself and can copy or destroy the handle automatically (as > Base_Object is a controlled object). > > Example_Record is a derived type of Base_Object which imitates a behavior of > a simple library which operates over some handles. For example, in this > example copying a handle preserves it unchanged. > > This tiny program was created by me as a model of my real Ada bindings for > Raptor C library, which produces a wrong behavior. > > Why Ada behaves in this counter-intuitive way? > > What should I do in similar situations when developing real Ada software? >