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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,400766bdbcd86f7c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!news.mv.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: This can't be done in Ada...or? Date: 11 Feb 2005 13:27:11 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1108139611.709714.36170@o13g2000cwo.googlegroups.com> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1108146432 30415 69.38.147.31 (11 Feb 2005 18:27:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 11 Feb 2005 18:27:11 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:8253 Date: 2005-02-11T13:27:11-05:00 List-Id: Jeff C writes: > Per Lindquist wrote: > > 3. does *not* cause any execution overhead if disabled. ... > > I say it can't be done in Ada. Please prove me wrong! > 3) Pragma Inline the procedure calls. Put the "if Logging_Enabled" > inside the logging procedures. Make the Logging_Enabled a static > constant. Compiler should optimize away the entire procedure call if > done properly (it does on GNAT and VADS for the cases I have tried) The compiler can optimize away everything inside the "if Logging_Enabled". But it can't optimize away the evaluation of the parameters unless it can prove the absence of side effects. For example: Trace.Error(..., "Bad value of X " & Debug_Info(X)); where Debug_Info is some user-defined function that produces useful debug info about some complicated data structure called X. It has no side effects, but the compiler doesn't know that, usually. I suppose you could always write Debug_Info like this: function Debug_Info(...) return String; pragma Inline(Debug_Info); -- Don't call this unless Logging_Enabled is True! function Debug_Info(...) return String is begin if Logging_Enabled then return The_Real_Debug_Info(...); else raise Program_Error; end if; end Debug_Info; But then you have to write two versions of Debug_Info for every type. So I'd say the original poster's statement, "it can't be done in Ada" is pretty true, if zero run-time overhead is required. In my code, I usually do as you suggested, but *also* add "if Logging_Enabled" or whatever around calls if the parameter evaluation could be expensive. This provides *almost* what the original poster asked for -- you need the annoying "if Logging_Enabled" only sometimes. - Bob