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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,f0ba82308a594485 X-Google-Attributes: gid103376,public From: "Jean-Pierre Rosen" Subject: Re: Right of Optimize Eager Evaluation Away Date: 1999/11/29 Message-ID: <81uhd2$nl4$1@wanadoo.fr>#1/1 X-Deja-AN: 554514846 References: <863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 X-Complaints-To: abuse@wanadoo.fr X-Trace: wanadoo.fr 943900898 24228 164.138.107.99 (29 Nov 1999 18:41:38 GMT) Organization: Adalog X-MSMail-Priority: Normal NNTP-Posting-Date: 29 Nov 1999 18:41:38 GMT Newsgroups: comp.lang.ada Date: 1999-11-29T18:41:38+00:00 List-Id: Laurent Guerby a �crit dans le message : 863dtqfo26.fsf@ppp-173-146.villette.club-internet.fr... > [I originally posted this in the 11.6 thread, but got no answer] > > If we have the following function: > > function Cond_T (C : in Boolean; If_True, If_False : in T) return T; > pragma Inline (Cond_T); > > function Cond_T (C : in Boolean; If_True, If_False : in T) return T is > begin > if C then > return If_True; > else > return If_False; > end if; > end Cond_T; > > And the following expression: > > C : constant Boolean := Some_Run_Time_Value_That_The_Compiler_Cannot_Guess; > > X : constant T := Cont_T (C, If_True => Super_Expensive_Function_Call_1, > If_False => Super_Expensive_Function_Call_2); > > The question is: is a smart Ada 95 compiler allowed to generate code > that looks like this: > > if C then > X := Super_Expensive_Function_Call_1; > else > X := Super_Expensive_Function_Call_2; > end if; > > that is to say, be lazy about its argument, and so might > save execution time. > The simplest solution in this case would be to pass pointers to the Super_Expensive_Function_Calls; This way, only the *pointers* are evaluated at the call, the functions are actually called only as necessary... -- --------------------------------------------------------- J-P. Rosen (Rosen.Adalog@wanadoo.fr) Visit Adalog's web site at http://pro.wanadoo.fr/adalog