From: Gautier write-only <gautier_niouzes@hotmail.com>
Subject: Re: Disabling string evaluation in a logging system
Date: Tue, 18 May 2010 02:32:38 -0700 (PDT)
Date: 2010-05-18T02:32:38-07:00 [thread overview]
Message-ID: <5b94cf13-b7e7-4079-97c6-87dd03f29933@o39g2000vbd.googlegroups.com> (raw)
In-Reply-To: de99764a-fe45-4207-ad34-ed0cf1978d59@c13g2000vbr.googlegroups.com
On 18 Mai, 09:48, dhenry <tfc.d...@gmail.com> wrote:
> In a language like C or C++, I would use the preprocessor:
> #define LOG(text, level) if (level > 0) { log.write (text, level) }
>
> I'm wondering how in Ada 95 and/or Ada 2005 I could write such a
> logging system (if it's possible). The goal is that logging should not
> be too intrusive in my code.
Yes. You can get the same in (and within) Ada with the magic of the
Inline pragma.
Gnatchop the following:
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
package Log is
procedure Write (Text: String; Level: Natural);
pragma Inline(Write);
end Log;
--
with Ada.Text_IO;
package body Log is
procedure Write (Text: String; Level: Natural) is
begin
if Level > 0 then
Ada.Text_IO.Put_Line("Log: " & Text);
end if;
end Write;
end Log;
--
with Log;
procedure Test_Opti_inline is
begin
Log.Write (Text => "Blabla...", Level => 5);
Log.Write (Text => "No no no!", Level => 0);
end;
--8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<---
Then:
gcc -S -gnatn test_opti_inline.adb
The string "No no no!" doesn't even appear in the assembler
listing :-)
HTH
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/
NB: For a direct answer, e-mail address on the following web site:
http://www.fechtenafz.ethz.ch/wm_email.htm
next prev parent reply other threads:[~2010-05-18 9:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-18 7:48 Disabling string evaluation in a logging system dhenry
2010-05-18 8:15 ` Dmitry A. Kazakov
2010-05-18 8:45 ` Dmitry A. Kazakov
2010-05-18 9:45 ` Cyrille
2010-05-18 10:26 ` Dmitry A. Kazakov
2010-05-18 12:10 ` Georg Bauhaus
2010-05-18 12:15 ` Georg Bauhaus
2010-05-18 12:54 ` Dmitry A. Kazakov
2010-05-18 9:32 ` Gautier write-only [this message]
2010-05-18 9:37 ` Gautier write-only
2010-05-18 11:27 ` Gautier write-only
2010-05-18 12:18 ` dhenry
2010-05-19 9:04 ` Stephen Leake
2010-05-19 12:38 ` Dmitry A. Kazakov
2010-05-19 18:02 ` (see below)
2010-05-19 19:08 ` Adam Beneschan
2010-05-18 10:13 ` stefan-lucks
2010-05-18 18:17 ` Jeffrey R. Carter
2010-05-18 18:40 ` tmoran
2010-05-19 7:47 ` dhenry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox