comp.lang.ada
 help / color / mirror / Atom feed
From: robert_dewar@my-dejanews.com
Subject: Re: Alternate to Unchecked_Conversion - Portable?
Date: 1999/02/25
Date: 1999-02-25T00:00:00+00:00	[thread overview]
Message-ID: <7b3glh$ml6$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 36d50d18.695962@nntp.concentric.net

In article <36d50d18.695962@nntp.concentric.net>,
  cjrgreen@concentric.net (Christopher Green) wrote:
> Such compilers (there are a few still in use) are, for
> reasons like this, virtually useless for the sort of
> programming in which address
> clauses,Unchecked_Conversion, or equivalence
> between C pointer types and Ada access types is
> important.

No, not at all.

They may be virtually useless for careless programmers who
do not distinguish between erroneous constructs and those
that may theoretically be non-portable but are in practice
portable.

We have four kinds of programming constructs explicitly
and implicitly mentioned here:

1) Using address clauses to achieve erroneous overlays as
   defined by RM83

2) Using address clauses in a legitimate manner

3) Using Unchecked conversion in general

4) Using Unchecked conversion to convert between Ada access
   types and C pointers

Now of these 4, ONLY 1) is erroneous in Ada 83, and a
competent Ada 83 programmer understands what is and what
is not erroneous, and avoids erroneous constructs.

The rest are not erroneous. In fact the word erroneous
appears in the section on UC only to remind you that the
resulting value must be valid.

Uses of 2) 3) 4) are possibly implementation dependent,
and a compiler can theoretically sabotage you by being
unreasonable, but here the principle that Chris states
is valid. A sensible programmer using these constructs
in a reasonable manner using sensible compilers will not
run into trouble.

But to casually lump erroneous constructs in with
implementation constructs is definitely sloppy, and
we have seen numerous instances of people having
trouble porting Ada 83 code to Ada 95 compilers because
of injudicious programmers writing erroneous code that
just happened to work.

A mantra that should be central to every programmer's
view of the universe is:

  "just because it works does not mean it is right"

A lot of programmers violate this because they don't know
enough to avoid violations.

In this particular case, the use of overlays to achieve the
effect of unchecked conversion is almost always a bad
programming choice, and leads you into unnecessary
implementation dependencies, even in Ada 95 where it
is no longer explicitly erroneous. It is almost always
better to use unchecked conversion of pointers (making
sure OF COURSE that you do not try to use pointers to
unconstrained arrays in this context!)



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-21  0:00 Alternate to Unchecked_Conversion - Portable? Steve Doiel
1999-02-21  0:00 ` Steve Quinlan
1999-02-22  0:00   ` robert_dewar
1999-02-21  0:00 ` Matthew Heaney
1999-02-22  0:00 ` Tom Moran
1999-02-22  0:00 ` robert_dewar
1999-02-22  0:00   ` Samuel Mize
1999-02-22  0:00 ` Christopher Green
1999-02-23  0:00   ` Matthew Heaney
1999-02-23  0:00     ` Samuel Mize
1999-02-24  0:00     ` robert_dewar
1999-02-25  0:00       ` Nick Roberts
1999-02-25  0:00         ` robert_dewar
1999-02-26  0:00           ` Nick Roberts
1999-02-26  0:00             ` Matthew Heaney
1999-02-27  0:00               ` Nick Roberts
1999-02-24  0:00   ` robert_dewar
1999-02-23  0:00     ` Christopher Green
1999-02-25  0:00       ` robert_dewar
1999-02-24  0:00         ` Christopher Green
1999-02-25  0:00           ` robert_dewar [this message]
1999-02-25  0:00             ` dennison
1999-02-25  0:00               ` Christopher Green
1999-02-26  0:00                 ` Tom Moran
1999-02-26  0:00                   ` robert_dewar
1999-02-26  0:00                 ` robert_dewar
1999-02-26  0:00                   ` Christopher Green
1999-03-01  0:00                     ` Nick Roberts
1999-03-01  0:00                       ` dewar
1999-03-01  0:00                         ` Nick Roberts
1999-02-26  0:00             ` Robert A Duff
1999-02-28  0:00               ` robert_dewar
1999-02-23  0:00     ` Christopher Green
1999-02-25  0:00       ` robert_dewar
1999-02-24  0:00         ` Christopher Green
1999-02-25  0:00           ` robert_dewar
1999-02-26  0:00             ` Dale Stanbrough
1999-02-26  0:00               ` Robert A Duff
replies disabled

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