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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,86b57370403509bc X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!o39g2000vbd.googlegroups.com!not-for-mail From: Gautier write-only Newsgroups: comp.lang.ada Subject: Re: Disabling string evaluation in a logging system Date: Tue, 18 May 2010 02:32:38 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5b94cf13-b7e7-4079-97c6-87dd03f29933@o39g2000vbd.googlegroups.com> References: NNTP-Posting-Host: 206.122.158.4 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1274175158 11521 127.0.0.1 (18 May 2010 09:32:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 18 May 2010 09:32:38 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o39g2000vbd.googlegroups.com; posting-host=206.122.158.4; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1064 Safari/532.5,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:11708 Date: 2010-05-18T02:32:38-07:00 List-Id: On 18 Mai, 09:48, dhenry 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