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: <7b3fk2$lnk$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 7b2j34$drp$3@plug.news.pipex.net

In article <7b2j34$drp$3@plug.news.pipex.net>,
  "Nick Roberts" <Nick.Roberts@dial.pipex.com> wrote:

> |> procedure Op (O : T) is
> |>
> |>   OO : constant TT := UC (O);
> |> begin
> If the type T were not a 'small' type (which can fit into
> one or two registers) -- and I think that's what the
> context of this thread suggests --
> I would be surprised by an optimising compiler which did
> make a copy. Whyever should it make a copy?


Well Nick, you seem to be operating as a user looking at
a specific case and wondering why it is not optimized,
rather than an implementor writing an optimizing compiler.
All I can say is come back when your optimizing compiler
is complete, and see if you handle this case, and if so
why and how it is a special case of a more general
optimization principle.

Obviously there are two quite separate objects here, and
indeed a programmer would expect that O'Address and
OO'Address would be different, so in the general case
I am not even sure the optimization is valid at all.
This is in fact a very delicate optimization, the
question of when you could treat initialized constants
as implicit renamings is indeed an interesting one.

Note of course that if you write

  OO : TT renames UC (O);

then an Ada 95 (but not necessarily an Ada 83) compiler
may routinely create a reference rather than a copy in
this situation. That's because of the important change
in Unchecked_Conversion semantics in Ada 95 that allows
return by reference.

I often find that users who do not understand compilers
and optimizing compilers in particular well are often in
a mode of looking at specific examples and saying "why is
this paticular case not generating this particular code?"

Humans are VERY good at special casing, but of course the
challenge in an optimizing compiler is to find general
safe optimization principles. Compilers that have lots
of special case optimization are exactly the ones that
have lead many programmers to distrust optimization :-)


-----------== 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 [this message]
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
replies disabled

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