comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Tricks Of The Trade: How To Compile Large Program On Two Very Different Compilers
Date: Thu, 05 Nov 2009 19:21:55 +0100
Date: 2009-11-05T19:21:56+01:00	[thread overview]
Message-ID: <4af317c4$0$6731$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <4fbfba1f-65ac-43d5-8328-61dcf075a1b1@13g2000prl.googlegroups.com>

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;



  parent reply	other threads:[~2009-11-05 18:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <81734679-bcfc-4d52-b5c2-104f0d75b592@i12g2000prg.googlegroups.com>
2009-11-04 19:27 ` Tricks Of The Trade: How To Compile Large Program On Two Very Different Compilers Hibou57 (Yannick Duchêne)
     [not found] ` <40fef45f-7203-47f1-8aae-7f0bdd23ea94@u36g2000prn.googlegroups.com>
     [not found]   ` <95a354e8-385b-4175-b5cd-d59598764750@w37g2000prg.googlegroups.com>
     [not found]     ` <7b8ca66e-ca6d-44ea-bad9-35b44bb8425a@12g2000pri.googlegroups.com>
2009-11-04 20:10       ` Jeffrey R. Carter
2009-11-11 20:51         ` sjw
     [not found] ` <687d5205-3e93-4b10-8d5d-e31d20e19e08@2g2000prl.googlegroups.com>
2009-11-05 10:02   ` Niklas Holsti
     [not found]     ` <b813c43f-5973-43ee-aa79-9fb90d6d077c@r24g2000prf.googlegroups.com>
2009-11-05 15:31       ` Georg Bauhaus
     [not found]         ` <1dac1c79-6cfe-46da-a5cf-7b0dd4b95775@z4g2000prh.googlegroups.com>
     [not found]           ` <4fbfba1f-65ac-43d5-8328-61dcf075a1b1@13g2000prl.googlegroups.com>
2009-11-05 18:21             ` Georg Bauhaus [this message]
2009-11-05 19:04       ` Jeffrey R. Carter
     [not found]         ` <74d8ae6e-a5f6-4add-b08f-6760c8d3d182@12g2000pri.googlegroups.com>
2009-11-07  5:59           ` Stephen Leake
2009-11-04 19:32 Hibou57 (Yannick Duchêne)
2009-11-05 10:26 ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox