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: 103376,c35edbbda4c7f58f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Conditional compilation in Ada? References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Tue, 16 Nov 2004 19:03:13 GMT NNTP-Posting-Host: 63.184.9.225 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1100631793 63.184.9.225 (Tue, 16 Nov 2004 11:03:13 PST) NNTP-Posting-Date: Tue, 16 Nov 2004 11:03:13 PST Xref: g2news1.google.com comp.lang.ada:6224 Date: 2004-11-16T19:03:13+00:00 List-Id: jtg wrote: > I am developing two applications which are very similar > and share the same source code. The only difference is > a small change in a fundamental data structure. Both versions of the > data structure are mostly handled the same way (within thousands of > lines of source code), but there are some 10 or 20 (number still > growing) places where minor changes are necessary. What is worse, > during the development every several hours I have to prepare > and run both the applications. To do this, I have to perform > "human preprocessing": find those places, comment lines > for app1, and uncomment lines for app2. This is very error prone and > I have already made a mistake. > > Any hints? Yes. Don't use preprocessing. It sounds as if you have a good use for a variant record: type Common_Stuff is record ... end record; type Variant_1_Stuff is record ... end record; type Variant_2_Stuff is record ... end record; type Data_Structure (Variant_1 : Boolean) is record Common : Common_Stuff; case Variant_1 is when True => Var_1 : Variant_1_Stuff; when False => Var_2 : Variant_2_Stuff; end case; end record; Then you can write Variant_1 : constant Boolean := ...; X : Data_Structure (Variant_1 => Variant_1); ... Common_Processing (Common => X.Common); if X.Variant_1 then Variant_1_Processing (Var_1 => X.Var_1); else Variant_2_Processing (Var_2 => X.Var_2); end if; If you anticipate additional variants, it's probably better to use an enumeration type for the discriminant: type Variant_ID is (Variant_1, Variant_2); type Data_Structure (Variant : Variant_ID) ... case X.Variant is when Variant_1 => Variant_1_Processing ... This is easily expanded by adding additional variants, and the compiler will tell you if you've missed anything. -- Jeff Carter "I've got to stay here, but there's no reason why you folks shouldn't go out into the lobby until this thing blows over." Horse Feathers 50