From: Jeffrey Carter <spam@spam.com>
Subject: Re: Preprocessor functionality equivalent ideas needed
Date: Thu, 11 Dec 2003 17:49:22 GMT
Date: 2003-12-11T17:49:22+00:00 [thread overview]
Message-ID: <C62Cb.7728$_r6.3754@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <3FD8726E.1000205@noplace.com>
Marin David Condic wrote:
> While I agree with the general concept of separate bodies for separate
> implementation-specific modules, I have occasionally run into situations
> where it would have been nice if I had a compiler directive of some sort
> to go one way or another depending on some condition. This is especially
> true where I might need to keep code portable between two different
> compilers. Also its a big problem when what needs to be different is in
> the *specification* of something. (Yes, I know, "One more layer of
> indirection...." can go fix it - but why should it be so hard?)
There are several ways to deal with needing multiple versions of the
spec. Sometimes you can use functions instead of constants:
package P is -- Version X
Num_Processors : constant := 4;
end P;
package P is -- Version Y
Num_Processors : constant := 256;
end P;
becomes
package P is
function Num_Processors return Positive;
end P;
Functions are sometimes not acceptable because the value needs to be static.
Sometimes you can have multiple versions with different names, and use
renaming to select the appropriate one:
package P_X is
Num_Processors : constant := 4;
Directory_Separator : constant Character := '\';
end P_X:
package P_Y is
Num_Processors : constant := 256;
Directory_Separator : constant Character := '/';
end P_Y;
with P_X;
package P renames P_X;
Now the values in P are static.
And while another layer of information hiding may be harder in the short
run, it's almost always easier in the long run.
--
Jeff Carter
"Sir Lancelot saves Sir Gallahad from almost certain temptation."
Monty Python & the Holy Grail
69
next prev parent reply other threads:[~2003-12-11 17:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-10 20:04 Preprocessor functionality equivalent ideas needed Greg Milford
2003-12-10 21:41 ` Ludovic Brenta
2003-12-11 17:12 ` sed and perl - yuck [Was Re: Preprocessor functionality equivalent ideas needed] Martin Krischik
2003-12-16 0:40 ` Waldek Hebisch
2003-12-16 20:52 ` Martin Krischik
2003-12-10 22:29 ` Preprocessor functionality equivalent ideas needed Georg Bauhaus
2003-12-12 5:52 ` Simon Wright
2003-12-11 1:07 ` Jeffrey Carter
2003-12-11 13:34 ` Marin David Condic
2003-12-11 17:49 ` Jeffrey Carter [this message]
2003-12-11 5:39 ` Steve
2003-12-11 16:59 ` Martin Krischik
-- strict thread matches above, loose matches on Subject: below --
2003-12-11 12:52 Lionel.DRAGHI
2003-12-11 15:51 Lionel.DRAGHI
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox