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,c35edbbda4c7f58f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!not-for-mail From: aschwarz@acm.org (skidmarks) Newsgroups: comp.lang.ada Subject: Re: Conditional compilation in Ada? Date: 23 Nov 2004 07:42:21 -0800 Organization: http://groups.google.com Message-ID: <35f054ea.0411230742.62e84f5d@posting.google.com> References: <419b5ff6$0$25329$9b4e6d93@newsread2.arcor-online.net> <41A28F3D.2030008@acm.org> NNTP-Posting-Host: 199.46.200.234 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1101224542 5170 127.0.0.1 (23 Nov 2004 15:42:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 23 Nov 2004 15:42:22 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:6379 Date: 2004-11-23T07:42:21-08:00 List-Id: > > > Package one body is > > Debug_Flag : Boolean := TRUE; // Note: this is a variable > // and placed in the spec file. > > function Is_Debug return Boolean is > begin -- Is_Debug > return Debug_Flag; > end Is_Debug; > pragma inline( Is_Debug ); > Sorry. I just read the original post. The advantage of using constants is that the compiler (should) remove the conditional branch which is never executed, viz. Debug_Flag := constant Boolean := TRUE; if ( Debug_Flag ) then null; // always executed else null; // never executed and the compiler will end if; // remove the code The function 'Is_Debug' with a pragma inline should have the same effect. Since the flag conditions the branch, it is possible to compile all required code variants and select them at run-time by using a variable flag instead of a constant. If you are willing to perform multiple builds, then a constant flag achieves much the same effect as a C/C++ conditional compilation. And, of course, the Is_Debug is thrown in as a 'plus'. art