comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: This can't be done in Ada...or?
Date: 11 Feb 2005 13:27:11 -0500
Date: 2005-02-11T13:27:11-05:00	[thread overview]
Message-ID: <wcck6pf54w0.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: xtadnQ1DlL2teJHfRVn-qw@comcast.com

Jeff C <jcreem@yahoo.com> 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



  reply	other threads:[~2005-02-11 18:27 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-11 16:33 This can't be done in Ada...or? Per Lindquist
2005-02-11 16:51 ` Duncan Sands
2005-02-12 19:55   ` Florian Weimer
2005-02-14  8:34     ` Per Lindquist
2005-02-14  8:17   ` Per Lindquist
2005-02-11 17:02 ` Jeff C
2005-02-11 18:27   ` Robert A Duff [this message]
2005-02-11 23:51     ` Ludovic Brenta
2005-02-11 23:52       ` Robert A Duff
2005-02-12 13:55     ` Duncan Sands
2005-02-12 14:58       ` Martin Krischik
2005-02-12 15:56         ` Martin Dowie
2005-02-12 19:02       ` Robert A Duff
2005-02-14  8:49     ` Per Lindquist
2005-02-11 17:08 ` Jerome Hugues
2005-02-14  9:05   ` Per Lindquist
2005-02-14 13:07     ` Georg Bauhaus
2005-02-12  1:10 ` Jeffrey Carter
2005-02-12 14:01   ` Duncan Sands
2005-02-13  0:27     ` Jeffrey Carter
2005-02-14  9:10       ` Per Lindquist
2005-02-15  0:40         ` Jeffrey Carter
2005-02-15  7:40           ` Per Lindquist
2005-02-15  8:39             ` OT: Google reply (Was: Re: This can't be done in Ada...or?) Adrien Plisson
2005-02-15  9:42               ` Per Lindquist
2005-02-15  8:27           ` This can't be done in Ada...or? Per Lindquist
2005-02-14 22:10             ` Manuel G. R.
2005-02-15  8:47             ` Mark Lorenzen
2005-02-15  9:09               ` Jacob Sparre Andersen
2005-02-15  9:31                 ` Mark Lorenzen
2005-02-15  9:48                   ` Jacob Sparre Andersen
2005-02-15 10:07                     ` Mark Lorenzen
2005-02-15 10:15                   ` Martin Dowie
2005-02-17 22:09                     ` Randy Brukardt
2005-02-18  6:53                       ` Martin Dowie
2005-02-15 13:46                   ` Robert A Duff
2005-02-15 13:41                 ` Robert A Duff
2005-02-15 16:30                   ` Per Lindquist
2005-02-15 19:38                     ` Martin Dowie
2005-02-15 20:20                     ` Robert A Duff
2005-02-17 21:52                   ` Simon Wright
2005-02-17 22:06               ` Randy Brukardt
2005-02-17 22:40                 ` Mark Lorenzen
2005-02-16  0:04             ` Jeffrey Carter
2005-02-16  0:09             ` Jeffrey Carter
2005-02-17  9:47               ` Per Lindquist
2005-02-17 22:36               ` Randy Brukardt
2005-02-14 15:21 ` Peter Amey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox