comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Mize <smize@imagin.net>
Subject: Re: Alternate to Unchecked_Conversion - Portable?
Date: 1999/02/22
Date: 1999-02-22T00:00:00+00:00	[thread overview]
Message-ID: <7aru71$iu6@news3.newsguy.com> (raw)
In-Reply-To: 7aqe04$uhl$1@nnrp1.dejanews.com

Just a couple of further points, I'm not disagreeing with Robert.

robert_dewar@my-dejanews.com wrote:
> In article <36d05e39.0@news.pacifier.com>,
>   "Steve Doiel" <nospam_steved@pacifier.com> wrote:
>> I discovered a technique for performing a similar
>> function to Unchecked_Conversion.  Locating two data
>> structures at the same address by defining the first
>> normally and then using an address clause to locate the
>> second at the same address as the first (as shown in the
>> following sample):
>>
>> My question is: is this portable?
> 
> Answer: this technique is standard and well known in Ada
> 95, though it was always wrong (erroneous) in Ada 83. It
> is definitely NOT portable, and in particular, and
> optimizer may get confused by the implicit aliasing, and
> you cannot complain if it does!

There are some architectures on which it's not even meaningful.
For instance, I don't expect this would be useful on a LISP
machine.

It does work on most compilers, especially if you use pragma
Volatile.

<language sniping on>

This seems to be the definition that is used by some advocates
of a language that shall remain nameless (but its initial is C).
Since several compilers support feature X, it's a "standard,
portable" idiom in that language.

<language sniping off>

And, in all fairness, that's sometimes a useful way to look at
such questions.


> It is usually just as simple (from a reader's point of
> view, and I sure hope that this is what you mean by simple)
> to use unchecked conversion of pointers, and much better
> defined, and likely to be more portable.

But be careful.  For example, if the pointed-at object is an
array of an unconstrained type, the access object is likely
to be TWO pointers: one to a "dope vector," and one to the
array data itself.  As another example, an access to an
object from a storage pool may not be a pointer at all, but
an offset address into the pool.  Robert knows all this, of
course, and his statement is a generalization -- all of which
have exceptions.

My point is that, if you're trying to look at one piece of
memory with two mappings, you have to know what this specific
specific compiler does on this specific architecture, in this
specific case.

It is an *extremely* non-portable idiom in the general case,
although specific instances may be fairly portable (in the
informal sense of the word).  I believe that this statement
is true in both C and Ada, although the C culture relies on
this particular idiom much more commonly.

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-22  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 ` robert_dewar
1999-02-22  0:00   ` Samuel Mize [this message]
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
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-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
1999-02-22  0:00 ` Tom Moran
replies disabled

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