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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx19.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Any Suggestion How To Accomplish A Debug Macro? References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1419970060 68.145.219.148 (Tue, 30 Dec 2014 20:07:40 UTC) NNTP-Posting-Date: Tue, 30 Dec 2014 20:07:40 UTC Date: Tue, 30 Dec 2014 13:07:41 -0700 X-Received-Bytes: 2566 X-Received-Body-CRC: 198467052 Xref: news.eternal-september.org comp.lang.ada:24296 Date: 2014-12-30T13:07:41-07:00 List-Id: On 14-12-30 04:14 AM, Simon Wright wrote: > Hubert writes: > >> I know there is no such thing as C #define's in Ada, but isn't there a >> way to make some sort of debug macro? >> In my C++ code I use a lot of statements like >> >> PRINT(DEBUG_CHANNEL, "TEXT" ); >> >> to print out debug messages and in release code, these defines aren't >> compiled. Is there any way to achieve something like this in Ada >> without surrounding it with an IF statement and a boolean flag? > > GNAT has pragma Debug[1]. I was always annoyed that this is controlled > by -gnata, which also controls assertions, but I see there's a pragma > Debug_Policy - stated to be equivalent to pragma Check_Policy (Debug). > > [1] https://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Debugging---A-Special-Case.html > Another more portable solution would be to declare a static constant somewhere, and use the value of that constant to decide if logging should occur. If the compiler/linker supports dead code elimination, then the debug code can be eliminated if that variable is set to False. Eg. package Debug_Logging is Debug_Enabled : constant Boolean := False; -- Edit this line procedure Log(Message : String); end Debug_Logging; with Debug_Logging; procedure Foo is begin -- if statement removed if Debug_Enabled is false if Debug_Enabled then Log("Entered Foo"); end if; end Foo; This works in GNAT, and might work in other compilers as well. Worst case is that the Debug_Enabled boolean get evaluated in multiple places, but that overhead of evaluating a Boolean might still be acceptable for a compiler that doesn't do dead code elimination. Brad