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: <7b2leu$ad$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 36d3bf1f.1891152@nntp.concentric.net

In article <36d3bf1f.1891152@nntp.concentric.net>,
  cjrgreen@concentric.net (Christopher Green) wrote:
> Unchecked conversion of C pointers to Ada access values
> is, in my experience, no more portable than using address
> clauses to alias structured types.  When the desired Ada
> object is an instance of an unconstrained type,
> converting a pointer is completely nonportable and
> usually impractical.

and also completely meaningless!

An unconstrained array pointer in Ada must have bounds,
and these bounds must come from somewhere. It is not just
that this attempted conversion is non-portable, it is
semantic nonsense.

There are two possible approaches that are likely to be
portable in practice and which make semantic sense.

If you know the bounds, e.g. they are implied by the logic
or by some other parameters that are passed, then you can
declare a local subtype of the array type with the right
bounds, and use a pointer to this constrained type.

If you don't know the bounds, then use a "big array" type
such as

   subtype Big_String is String (Positive);
   type Big_String_Ptr is access Big_String;

now of course once you get a value of type Big_String_Ptr
using Unchecked_Conversion, it is up to you not to access
the array value outside its real bounds, but there is no
magic to prevent this in this case!

-----------== 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 ` Matthew Heaney
1999-02-21  0:00 ` Steve Quinlan
1999-02-22  0:00   ` robert_dewar
1999-02-22  0:00 ` Tom Moran
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 [this message]
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
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-25  0:00             ` dennison
1999-02-25  0:00               ` Christopher Green
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                 ` Tom Moran
1999-02-26  0:00                   ` robert_dewar
1999-02-26  0:00             ` Robert A Duff
1999-02-28  0:00               ` robert_dewar
1999-02-22  0:00 ` robert_dewar
1999-02-22  0:00   ` Samuel Mize
replies disabled

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