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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Is this a bug in my code or the compiler? Date: Fri, 12 Jun 2015 18:15:59 +0200 Organization: cbb software GmbH Message-ID: <1p71vf5ckbudu$.1qcb9ot1jpysk.dlg@40tude.net> References: <4f4cd4b1-0a6d-441b-a4f7-98add70e4e1e@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: evoS9sCOdnHjo0GRLLMU1Q.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:26284 Date: 2015-06-12T18:15:59+02:00 List-Id: On Fri, 12 Jun 2015 08:56:23 -0700 (PDT), David Botton wrote: > Given: > > function Token_Start (Source : in out Awesome.Source.Source_Type'Class) > return Character; > function Token_End (Source : in out Awesome.Source.Source_Type'Class) > return String; > > The following works: > > function Get_Token_Text (Source : in out Awesome.Source.Source_Type'Class) > return String > is > N : Character := Token_Start (Source); > begin > return N & Token_End (Source); > end Get_Token_Text; > > The following does not work: > > function Get_Token_Text (Source : in out Awesome.Source.Source_Type'Class) > return String > is > begin > return Token_Start (Source) & Token_End (Source); > end Get_Token_Text; > > Token_End is never called and only the value of Token_Start. That is one of the reasons why in-out's were not allowed for functions in Ada 83. The code is clearly erroneous because the computation order is not defined. Possibly Token_End is called before Token_Start! P.S. When in-out's for functions were discussed I proposed not to allow them as operands in operations that do not state the evaluation order. E.g. function Foo (X : in out T) return Boolean; Foo (A) and Foo (A) -- Illegal Foo (A) and then Foo (A) -- Legal P.P.S. It would become even worse with fine-grained parallelism, as Georg keep on suggesting. If Token_Start (Source) and Token_End (Source) were running in parallel on different cores, that would be great fun! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de