comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam@spam.com>
Subject: Re: Conditional compilation in Ada?
Date: Tue, 16 Nov 2004 19:03:13 GMT
Date: 2004-11-16T19:03:13+00:00	[thread overview]
Message-ID: <R9smd.688$Tq6.286@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <cndgus$9g6$1@korweta.task.gda.pl>

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




  parent reply	other threads:[~2004-11-16 19:03 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-16 18:30 Conditional compilation in Ada? jtg
2004-11-16 18:45 ` Marius Amado Alves
2004-11-16 20:41   ` Nick Roberts
2004-11-17  8:36     ` Alex R. Mosteo
2004-11-16 19:03 ` Jeffrey Carter [this message]
2004-11-16 19:13   ` Hyman Rosen
2004-11-16 19:41     ` Björn Lundin
2004-11-16 20:08     ` tmoran
2004-11-16 20:27       ` Hyman Rosen
2004-11-16 23:49         ` Jim Rogers
2004-11-16 20:43     ` Martin Dowie
2004-11-16 19:06 ` tmoran
2004-11-17  9:39   ` Adrien Plisson
2004-11-17 16:39     ` Jacob Sparre Andersen
2004-11-17  2:44 ` Steve
2004-11-17 20:30   ` Jeffrey Carter
2004-11-18  4:09     ` Steve
2004-11-18  6:49       ` Martin Dowie
2004-11-18 15:17         ` Georg Bauhaus
2004-11-18 19:12           ` Martin Dowie
2004-11-18 17:34         ` Jeffrey Carter
2004-11-18 17:44       ` Jeffrey Carter
2004-11-18 18:03         ` Alex R. Mosteo
2004-11-19  3:00           ` Steve
2004-11-19 21:35             ` Simon Wright
2004-11-20  2:56               ` Steve
2004-11-20 16:57                 ` Simon Wright
2004-11-17  9:28 ` Martin Krischik
2004-11-17 13:39   ` Stephen Leake
2004-11-17 10:02 ` Frank Piron
2004-11-17 12:32   ` Georg Bauhaus
2004-11-17 14:44     ` Dmitry A. Kazakov
2004-11-18 15:23       ` Georg Bauhaus
2004-11-18 22:10         ` Brian May
2004-11-19  9:03           ` Martin Krischik
2004-11-20 17:31             ` Georg Bauhaus
2004-11-21  9:14               ` Martin Krischik
2004-12-12  0:36               ` Lionel Draghi
2004-12-12  0:17             ` How to switch off those damm warnings about unknows pragma Lionel Draghi
2004-12-13 11:10               ` Georg Bauhaus
2004-12-13 15:07               ` Peter Amey
2004-11-20  1:05         ` Conditional compilation in Ada? Dr. Adrian Wrigley
2004-11-20 17:25           ` Georg Bauhaus
2004-11-23  1:15           ` Arthur Schwarz
2004-11-23 15:42             ` skidmarks
2004-11-17 12:27 ` Marin David Condic
  -- strict thread matches above, loose matches on Subject: below --
2004-11-19  9:13 Christoph Karl Walter Grein
replies disabled

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