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 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 22 Oct 92 16:56:50 GMT From: visicom!amstel!rlk@nosc.mil (Bob Kitzberger) Subject: Re: Platform specific sources Message-ID: List-Id: tim@trident.datasys.swri.edu (Timothy J. Barton) writes: >Is there a "superior" method for supporting platform specific >features in the same source code using Ada? IMHO, the superior method is to encapsulate target-specific code into a (sub)unit (package, procedure, etc.) that can be separately compiled. Two main approaches: A. Subunits package My_System is package Target_Specifics is separate; ... Then, have 'n' version of the separate package Target_Specifics, in separate, uniquely named files (Target_sparc.ada, Target_mc680x0.ada, etc.) Of course, only compile the file that matches the target you are building your system for. (caveat: there are performance issues related to use of subunits. See "Optimization Issues Relating to Subunits", Tom Burger, Ada Letters May/June 1992.) B. Packages with Target_Specifics; package My_System is ... As above, write a version of Target_Specifics for each target you are supporting. For some target dependencies, it can be difficult to encapsulate the dependencies into units or subunits. For finer granularity of conditional compilation, use constants: type Target is ( MC680x0, 80x86, SPARC); This_Target : constant Target := MC680x0; ... if This_Target = SPARC then ... etc. Reasonable compilers will optimize away code inside of conditional statements, if the conditional statically evaluates to false. .Bob. ---------------- Bob Kitzberger VisiCom Laboratories, Inc. rlk@visicom.com 10052 Mesa Ridge Court, San Diego CA 92121 USA +1 619 457 2111 FAX +1 619 457 0888