comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: conversions between fixed-point types
Date: Mon, 28 Sep 2009 08:15:17 -0700 (PDT)
Date: 2009-09-28T08:15:17-07:00	[thread overview]
Message-ID: <aa190c6b-f179-4202-9072-02dcf83cb2c8@v23g2000pro.googlegroups.com> (raw)
In-Reply-To: h9l9aa$rb9$1@news.albasani.net

On Sep 26, 7:43 am, Dirk Herrmann <fight_s...@invalid.invalid> wrote:

> Whom could I contact to figure out whether this is an omission in the language
> definition (which could then be fixed) or whether it is intentional?  I would
> also like to ask about another issue:
>
> Dirk Herrmann wrote:
>
>  > Robert A Duff wrote:
>  >> By the way, you can say:
>  >>
>  >>     for T'Small use T'Delta;
>  >>
>  >> to avoid repeating yourself.
>  >
>  > I have tried that, especially since the very same recommendation was
>  > given in the Barnes book "Ada 2005".  But, GNAT gives an error message.
>  > It seems that the very moment you reference T'Delta the type T gets
>  > "frozen" such that  the "use" statement itself freezes T before it can
>  > modify it.  I don't know if this is what the authors of the reference
>  > manual had intended, but GNAT interprets it that way.

Although at first glance it seems like you should be able to do this,
I don't think it's likely that the RM could make this work in the
general case.  The rules do say that the occurrence of T'Delta causes
freezing; I believe this is part of the rule that an expression causes
freezing (except for nonstatic expressions used in parameter or
component defaults and some other cases).  Here, T'Delta is a static
expression and thus requires T to be frozen.

If we were to make an exception that, say, a representation attribute
of T does not cause freezing if it occurs in another representation
clause for T, you could end up with some interesting situations:

   type Arr is array (1 .. 5) of Boolean;
   for A'Size use A'Component_Size * 8;
   for A'Component_Size use A'Size - 14;

and now the compiler has to figure out how to solve for two
variables.  I suppose it's possible to write RM rules in such a way as
to prevent things like this while allowing the 'Small/'Delta case, but
this either requires some pretty complex rules, or rules that just
spell out a number of special cases (such as saying "An expression
causes freezing except in the one particular clause FOR T'SMALL USE
T'DELTA).  Neither one is going to be appealing particularly for such
a small gain---it doesn't give programmers the ability to do anything
that couldn't be accomplished easily with just a tiny bit more
effort.

Bottom line: it isn't possible to make the language make everything
work that looks like it should work.  Ada is, after all, a Programming
Language and not a Mind-Reading Machine.

                                        -- Adam




  reply	other threads:[~2009-09-28 15:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 21:35 conversions between fixed-point types Dirk Herrmann
2009-09-18 22:42 ` Adam Beneschan
2009-09-19 12:41 ` Dirk Herrmann
2009-09-19 14:48   ` John B. Matthews
2009-09-20  8:15     ` Dirk Herrmann
2009-09-20 14:22       ` Robert A Duff
2009-09-20 18:55         ` Dirk Herrmann
2009-09-20 20:34           ` Simon Clubley
2009-09-23 20:46             ` Dirk Herrmann
2009-09-27 17:15               ` Simon Clubley
2009-09-27 19:22           ` sjw
2009-09-28 20:18             ` Dirk Herrmann
2009-09-28 18:37           ` Robert A Duff
2009-09-28 20:50             ` Dirk Herrmann
2009-09-20 15:18       ` John B. Matthews
2009-09-20 19:13         ` Dirk Herrmann
2009-09-20 20:09       ` tmoran
2009-09-21 17:24       ` Jeffrey R. Carter
2009-09-23 20:57         ` Dirk Herrmann
2009-09-23 22:28           ` Jeffrey R. Carter
2009-09-24  1:05             ` Adam Beneschan
2009-09-24  3:57               ` Jeffrey R. Carter
2009-09-25  8:47               ` Stuart
2009-09-25 20:41                 ` sjw
2009-09-25 21:58                   ` Jeffrey R. Carter
2009-09-28 13:40                   ` Stuart
2009-09-26 14:43                 ` Dirk Herrmann
2009-09-28 15:15                   ` Adam Beneschan [this message]
2009-09-26 14:31               ` Dirk Herrmann
2009-09-19 18:38   ` tmoran
2009-09-20  8:22 ` sjw
replies disabled

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