From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,MSGID_SHORT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 22 Sep 92 20:22:07 GMT From: pitt.edu!gvls1!aviary!dmarshal@gatech.edu (Dave Marshall) Subject: Re: conditional compiles ? Message-ID: <1743@aviary.Stars.Reston.Unisys.COM> List-Id: 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