comp.lang.ada
 help / color / mirror / Atom feed
* Validity of renamed objects?
@ 2014-04-01 13:04 Jacob Sparre Andersen
  2014-04-01 13:44 ` J-P. Rosen
  2014-04-01 13:55 ` Markus Schöpflin
  0 siblings, 2 replies; 4+ messages in thread
From: Jacob Sparre Andersen @ 2014-04-01 13:04 UTC (permalink / raw)


I've been reading section 8.5.1 in the LRM, and I can't figure out when
the compiler is supposed to check the validity of a renamed object.

An example:

procedure Renaming_1 is
   Object  : String (1 .. 9) := "dead beef";
   Index   : Natural := 0;
   Renamed : Character renames Object (Index);
begin
   Index := (Object'First + Object'Last) / 2;
   if Renamed /= ' ' then
      raise Program_Error
        with "Expected Renamed to match the changed value of Index.";
   end if;
end Renaming_1;

1) Should I get a Constraint_Error when Renamed is declared?

2) What will the value of Renamed be after Index has been changed?

Greetings,

Jacob

PS: I know what the version of GNAT I have at hand does, but what it
    does is not completely obvious from my reading of the LRM.
-- 
»But you have to be a bit wary of a ship that collects
 snowflakes.«                                  -- Diziet Sma

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Validity of renamed objects?
  2014-04-01 13:04 Validity of renamed objects? Jacob Sparre Andersen
@ 2014-04-01 13:44 ` J-P. Rosen
  2014-04-01 13:55 ` Markus Schöpflin
  1 sibling, 0 replies; 4+ messages in thread
From: J-P. Rosen @ 2014-04-01 13:44 UTC (permalink / raw)


Le 01/04/2014 15:04, Jacob Sparre Andersen a écrit :
> I've been reading section 8.5.1 in the LRM, and I can't figure out when
> the compiler is supposed to check the validity of a renamed object.
> 
> An example:
> 
> procedure Renaming_1 is
>    Object  : String (1 .. 9) := "dead beef";
>    Index   : Natural := 0;
>    Renamed : Character renames Object (Index);
> begin
>    Index := (Object'First + Object'Last) / 2;
>    if Renamed /= ' ' then
>       raise Program_Error
>         with "Expected Renamed to match the changed value of Index.";
>    end if;
> end Renaming_1;
> 
> 1) Should I get a Constraint_Error when Renamed is declared?
Yes
> 2) What will the value of Renamed be after Index has been changed?
> 

Assuming Index is 1 (in order to avoid Constraint_Error), Renamed is
unchanged.

The principle is that when you elaborate the renaming declaration, you
evaluate the renamed object, and from then on the renaming identifier
designates that object. It's not a macro!


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Validity of renamed objects?
  2014-04-01 13:04 Validity of renamed objects? Jacob Sparre Andersen
  2014-04-01 13:44 ` J-P. Rosen
@ 2014-04-01 13:55 ` Markus Schöpflin
  2014-04-01 18:35   ` Jacob Sparre Andersen
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Schöpflin @ 2014-04-01 13:55 UTC (permalink / raw)


Am 01.04.2014 15:04, schrieb Jacob Sparre Andersen:

> I've been reading section 8.5.1 in the LRM, and I can't figure out when
> the compiler is supposed to check the validity of a renamed object.
>
> An example:
>
> procedure Renaming_1 is
>     Object  : String (1 .. 9) := "dead beef";
>     Index   : Natural := 0;
>     Renamed : Character renames Object (Index);
> begin
>     Index := (Object'First + Object'Last) / 2;
>     if Renamed /= ' ' then
>        raise Program_Error
>          with "Expected Renamed to match the changed value of Index.";
>     end if;
> end Renaming_1;
>
> 1) Should I get a Constraint_Error when Renamed is declared?

Yes, see 8.5(3).

"Object (Index)" is evaluated when the renaming declaration is elaborated.

Markus


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Validity of renamed objects?
  2014-04-01 13:55 ` Markus Schöpflin
@ 2014-04-01 18:35   ` Jacob Sparre Andersen
  0 siblings, 0 replies; 4+ messages in thread
From: Jacob Sparre Andersen @ 2014-04-01 18:35 UTC (permalink / raw)


Markus Schöpflin <no.spam@spam.spam> writes:
> Am 01.04.2014 15:04, schrieb Jacob Sparre Andersen:

>> I've been reading section 8.5.1 in the LRM, and I can't figure out
>> when the compiler is supposed to check the validity of a renamed
>> object.

> Yes, see 8.5(3).
>
> "Object (Index)" is evaluated when the renaming declaration is
> elaborated.

Yes.  Reading that paragraph it is quite clear.  Thanks!  (Also to
Jean-Pierre.)

Greetings,

Jacob
-- 
"If you think Tuck has said something that is completely
 wrong, you are almost certainly missing something :-)"


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-01 18:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01 13:04 Validity of renamed objects? Jacob Sparre Andersen
2014-04-01 13:44 ` J-P. Rosen
2014-04-01 13:55 ` Markus Schöpflin
2014-04-01 18:35   ` Jacob Sparre Andersen

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