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: a07f3367d7,8cbb5d23e501c27a X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 05 Nov 2009 19:21:55 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Tricks Of The Trade: How To Compile Large Program On Two Very Different Compilers References: <81734679-bcfc-4d52-b5c2-104f0d75b592@i12g2000prg.googlegroups.com> <687d5205-3e93-4b10-8d5d-e31d20e19e08@2g2000prl.googlegroups.com> <4af2a2cd$0$26303$4f793bc4@news.tdc.fi> <4af2efd8$0$6564$9b4e6d93@newsspool4.arcor-online.net> <1dac1c79-6cfe-46da-a5cf-7b0dd4b95775@z4g2000prh.googlegroups.com> <4fbfba1f-65ac-43d5-8328-61dcf075a1b1@13g2000prl.googlegroups.com> In-Reply-To: <4fbfba1f-65ac-43d5-8328-61dcf075a1b1@13g2000prl.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <4af317c4$0$6731$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 05 Nov 2009 19:21:56 CET NNTP-Posting-Host: bad0ed80.newsspool2.arcor-online.net X-Trace: DXC=0jLPnZ_nEk2Tia]Ho99G50A9EHlD;3Yc24Fo<]lROoR18kF:Lh>_cHTX3j=YlR4?C;ea?3 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:9004 Date: 2009-11-05T19:21:56+01:00 List-Id: ChristopherL schrieb: > Does Ada have anything similar to the following C preprocessor > directives: > > #ifdef TABLE_SIZE > --Add Code Here > #elif TABLE_SIZE < 50 > --Add Code Here > #endif > I had hesitated to mention a preprocessor. You can use M4, or cpp. However, dead code elimination is another option, stays within the language and insofar seems more manageable (cases don't get lost accross units when they are in types, not #conditionals, for example.) (To seems more manageable to me at least, I have lost hair in missing #else, missing code, missing test cases, and similar features of conditional program text. The separate directories solution (as long as the number of decisions is small) is no less checkable, and, I think, no more prone to errors than placing the code between preprocessor conditionals.) Small example that reduces the need for conditional text to one constant. It can be replaced using a preprocessor (or script or human) that needs not support conditionals. Dead code elimination may work: package Control is type Capacity is range 1 .. 8_000; type Table_Size is (Small, Big); for Table_Size use (Small => 10, Big => 1000); for Table_Size'Size use Capacity'Size; Mode : constant Table_Size := Small; -- <- adjust per system procedure Start; end Control; with Interfaces; with Ada.Unchecked_Conversion; package body Control is function To_Capacity is new Ada.Unchecked_Conversion (Table_Size, Capacity); package Small_System is procedure Run; private Last : constant Capacity := To_Capacity (Small); Data_Store : array (Capacity range 1 .. Last) of Interfaces.Unsigned_8; end Small_System; package Big_System is procedure Run; private Last : constant Capacity := To_Capacity (Big); Data_Store : array (Capacity range 1 .. Last) of Interfaces.Unsigned_8; -- ... other differences end Big_System; procedure Start is begin case Mode is when Small => Small_System.Run; when Big => Big_System.Run; end case; end; package body Small_System is separate; package body Big_System is separate; end Control;