comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Mize <smize@imagin.net>
Subject: Re: PRECOMPILATION
Date: 1999/02/19
Date: 1999-02-19T00:00:00+00:00	[thread overview]
Message-ID: <7ajv1n$23v0@news1.newsguy.com> (raw)
In-Reply-To: 7aickf$pb4$1@news-1.news.gte.net

Rakesh Malhotra <rakesh.malhotra@pop.safetran.com> wrote:
> Samuel Mize wrote:
[about preprocessors forcing you to address portability issues
 throughout your code]

> Would it be possible to give an Ada example of how you would do what you
> have suggested in your message above  ? i.e. what kind of things does
> one put into the platform specific packages, does one not land up with
> having to maintain many such packages versus just 1 file in the C case
> etc ?    Some code that highlights your explanation will help.

I don't have an example handy.  I assume there would be some useful
tutorial or example material at www.adahome.com or the ACM SigAda
web site.

Here's a sketch.

Suppose you want to use a system call to get the current time.
As I recall, there are at least three different "standard" Unix
OS calls to do this, each of which uses a different data structure.
A given Unix box will provide at least one of these.  And I assume
Windows does something different.

An Ada programmer would decide what representation of time is best
in this program, and write a package that makes the system call,
extracts time to the desired representation, and returns it.  Thus,
the entire program is insulated from the differences between systems,
except inside one package.

(That package being Ada.Calendar, in this example.)

Now, a sterotypical C programmer believes that preprocessor directives
are much more efficient than procedure calls.  So he would use #ifdefs
to select the right call and data structure.  If he is really worried
about performance, he'll put the #ifdefs in-line in the code.  If he
is a little less worried about performance, he'll put the #ifdefs into
a macro that makes the right call and puts the current time into a
global data structure.

The Ada programmer will trust the compiler to optimize the code,
instead of trying to do so by hand.  This is aided by pragma Inline,
which tells the compiler it may treat a procedure definition as if it
were a preprocessor macro, if convenient.

I hope this is enough to give you an idea.  Look for tutorials and
books on portability, and on design encapsulation.  The book "Ada
Quality and Style" has a section on portability, you may find that
useful.  AQ&S is available electronically for free, you can find it
via adahome, one specific URL is:

  http://wuarchive.wustl.edu/languages/ada/ajpo/docs/style-guide/
    95style/html/cover.html

Best,
Sam Mize

-- 
Samuel Mize -- smize@imagin.net (home email) -- Team Ada
Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam




  reply	other threads:[~1999-02-19  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-09  0:00 PRECOMPILATION =:-) Vincent
1999-02-09  0:00 ` PRECOMPILATION Tom Moran
1999-02-10  0:00   ` PRECOMPILATION Pascal MALAISE
1999-02-10  0:00     ` PRECOMPILATION Tom Moran
1999-02-09  0:00 ` PRECOMPILATION Marin David Condic
1999-02-09  0:00 ` PRECOMPILATION Tucker Taft
1999-02-10  0:00   ` PRECOMPILATION Fraser Wilson
1999-02-18  0:00   ` PRECOMPILATION Samuel Mize
1999-02-18  0:00     ` PRECOMPILATION robert_dewar
1999-02-18  0:00     ` PRECOMPILATION Rakesh Malhotra
1999-02-19  0:00       ` Samuel Mize [this message]
1999-02-28  0:00     ` PRECOMPILATION Robert A Duff
1999-02-09  0:00 ` PRECOMPILATION Larry Kilgallen
1999-02-09  0:00   ` PRECOMPILATION Pascal MALAISE
1999-02-09  0:00     ` PRECOMPILATION Tom Moran
1999-02-10  0:00       ` PRECOMPILATION dennison
1999-02-10  0:00       ` PRECOMPILATION Corey Ashford
1999-02-10  0:00       ` PRECOMPILATION robert_dewar
1999-02-09  0:00     ` PRECOMPILATION Tucker Taft
1999-02-09  0:00     ` PRECOMPILATION Tom Moran
1999-02-10  0:00       ` PRECOMPILATION Pascal MALAISE
1999-02-10  0:00         ` PRECOMPILATION Tom Moran
1999-02-11  0:00           ` PRECOMPILATION Pascal MALAISE
1999-02-12  0:00             ` PRECOMPILATION robert_dewar
1999-02-14  0:00               ` PRECOMPILATION Pascal MALAISE
replies disabled

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