comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pogner.demon.co.uk>
Subject: Re: what is happening here? (access types & discriminants...)
Date: 2000/03/19
Date: 2000-03-19T00:00:00+00:00	[thread overview]
Message-ID: <x7vzorv9oqj.fsf@pogner.demon.co.uk> (raw)
In-Reply-To: dale-1903002134440001@192.168.0.2

dale@cs.rmit.edu.au (Dale Stanbrough) writes:

> I've got the equivalent of the following code...
> 
> with ada.strings.unbounded; use ada.strings.unbounded;
> 
> package ua is
>    type Unbounded_Array     is array  (Positive range <>) of Unbounded_String;
>    type Unbounded_Array_Ptr is access Unbounded_Array;
> 
> 
>   i_dont_understand : unbounded_Array_ptr (1..100);
> end ua;
> 
> 
> Not quite sure what the definition of i_dont_understand is doing...

Judging by this experiment,

  with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
  with Ada.Text_Io; use Ada.Text_Io;

  procedure Ua is

    type Unbounded_Array     is array  (Positive range <>) of Unbounded_String;
     type Unbounded_Array_Ptr is access Unbounded_Array;


    I_Dont_Understand : Unbounded_Array_Ptr (13 .. 42)
       := new Unbounded_Array (13 .. 42);

    Me_Neither : Unbounded_Array_Ptr
       := new Unbounded_Array (14 .. 43);

  begin
    Put_Line ("f" & I_Dont_Understand'First'Img &
	      " l" & I_Dont_Understand'Last'Img);
    Put_Line ("f" & Me_Neither'First'Img &
	      " l" & Me_Neither'Last'Img);
  --   I_Dont_Understand := Me_Neither;               ------------------ CE
  --   Put_Line ("f" & I_Dont_Understand'First'Img &
  -- 	    " l" & I_Dont_Understand'Last'Img);
    I_Dont_Understand.all := Me_Neither.all;
    Put_Line ("f" & I_Dont_Understand'First'Img &
	      " l" & I_Dont_Understand'Last'Img);
    Me_Neither := new Unbounded_Array (13 .. 43);
    Put_Line ("f" & Me_Neither'First'Img &
	      " l" & Me_Neither'Last'Img);
  end Ua;

where the commented-out bit raises Constraint_Error, we've declared
i_dont_understand as a pointer capable of pointing only to arrays with
the designated constraint.

So an array assignment (of the right length) is OK, but a pointer
assignment with different constraints isn't.




  reply	other threads:[~2000-03-19  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-19  0:00 what is happening here? (access types & discriminants...) Dale Stanbrough
2000-03-19  0:00 ` Simon Wright [this message]
2000-03-19  0:00 ` Robert Dewar
2000-03-20  0:00   ` Dale Stanbrough
2000-03-21  0:00     ` Robert Dewar
replies disabled

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