From: pitt.edu!gvls1!aviary!dmarshal@gatech.edu (Dave Marshall)
Subject: Re: conditional compiles ?
Date: 22 Sep 92 20:22:07 GMT [thread overview]
Message-ID: <1743@aviary.Stars.Reston.Unisys.COM> (raw)
In article <1992Sep22.115353.27412@umbc3.umbc.edu>, dipto@umbc4.umbc.edu (Dipto
Chakravarty) writes:
>
> I am new to Ada, and was wondering how to do conditional compiles under
> an Ada program. Conditional compiles using #ifdef and #endif, etc.,
> allows us to maintain a large software which has several system specific
> routines using C.
>
> Please reply by email, as I am not a regular "rn" reader. Thanx in advance.
>
> .
It's not possible to use conditional compilation in Ada like you can in C.
However, by using a Boolean parameter to a function, procedure, or generic
package or subprogram, you can achieve the same effect. (Examples below.)
Paragraph 2 of Section 10.6 of the LRM states:
A compiler may find that some statements or subprograms will never be executed,
for example, if their execution depends on a condition known to be FALSE. The
corresponding object machine code can then be omitted. This rule permits the
effect of conditional compilation within the language.
Examples:
(I didn't compile these, so don't sue me if they're not exactly right.)
function MY_FUNCTION ( A : in INTEGER, DEBUG: in BOOLEAN) is
begin
if DEBUG then
-- some debug code
end if;
-- and so on
end MY_FUNCTION;
The procedure example is equally trivial.
I think that the way to give a compiler the best chance to optimize the
code away is to use the conditional parameter as a parameter for
instantiating a generic package or subprogram.
generic
DEBUG : BOOLEAN;
package MY_PACKAGE is
procedure DO_WAH;
end MY_PACKAGE;
Now implement the body of MY_PACKAGE and surround your conditional code
with "if"s on DEBUG. When you instantiate the package, the compiler
should be able to do what's right.
package MY_DEBUG_TEST is new MY_PACKAGE ( DEBUG => TRUE);
OR
package MY_FINAL_PRODUCT is new MY_PACKAGE ( DEBUG => FALSE);
You can do the same thing with procedures.
generic
DEBUG : BOOLEAN;
procedure MY_TEST_PROCEDURE;
--
Dave Marshall
dmarshal@stars.reston.unisys.com
next reply other threads:[~1992-09-22 20:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-09-22 20:22 Dave Marshall [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-09-29 16:37 conditional compiles ? Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox