comp.lang.ada
 help / color / mirror / Atom feed
* Re: what is happening here? (access types & discriminants...)
  2000-03-19  0:00 what is happening here? (access types & discriminants...) Dale Stanbrough
@ 2000-03-19  0:00 ` Simon Wright
  2000-03-19  0:00 ` Robert Dewar
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Wright @ 2000-03-19  0:00 UTC (permalink / raw)


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.




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

* what is happening here? (access types & discriminants...)
@ 2000-03-19  0:00 Dale Stanbrough
  2000-03-19  0:00 ` Simon Wright
  2000-03-19  0:00 ` Robert Dewar
  0 siblings, 2 replies; 5+ messages in thread
From: Dale Stanbrough @ 2000-03-19  0:00 UTC (permalink / raw)


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...


Thanks,

Dale




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

* Re: what is happening here? (access types & discriminants...)
  2000-03-19  0:00 what is happening here? (access types & discriminants...) Dale Stanbrough
  2000-03-19  0:00 ` Simon Wright
@ 2000-03-19  0:00 ` Robert Dewar
  2000-03-20  0:00   ` Dale Stanbrough
  1 sibling, 1 reply; 5+ messages in thread
From: Robert Dewar @ 2000-03-19  0:00 UTC (permalink / raw)


In article <dale-1903002134440001@192.168.0.2>,
  dale@cs.rmit.edu.au (Dale Stanbrough) wrote:
>   i_dont_understand : unbounded_Array_ptr (1..100);
> end ua;
>
> Not quite sure what the definition of i_dont_understand is
doing...


Not quite clear what you are asking, this is simply a
constrained subtype, no different conceptually from

 x : integer range 1 .. 100;


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: what is happening here? (access types & discriminants...)
  2000-03-19  0:00 ` Robert Dewar
@ 2000-03-20  0:00   ` Dale Stanbrough
  2000-03-21  0:00     ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Dale Stanbrough @ 2000-03-20  0:00 UTC (permalink / raw)


Robert Dewar wrote:

> Not quite clear what you are asking, this is simply a
> constrained subtype, no different conceptually from
> 
>  x : integer range 1 .. 100;



Does the declartion cause the pointer to only be able to point
at arrays from 1..100? If so I didn't know you could constrain
pointers in such a way.


Dale




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

* Re: what is happening here? (access types & discriminants...)
  2000-03-20  0:00   ` Dale Stanbrough
@ 2000-03-21  0:00     ` Robert Dewar
  0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2000-03-21  0:00 UTC (permalink / raw)


In article <dale-2003000749300001@192.168.0.2>,
  dale@cs.rmit.edu.au (Dale Stanbrough) wrote:

> Does the declartion cause the pointer to only be able to point
> at arrays from 1..100?

yes

> If so I didn't know you could constrain
> pointers in such a way.

It is a standard Ada 83 feature ...


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-03-21  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-19  0:00 what is happening here? (access types & discriminants...) Dale Stanbrough
2000-03-19  0:00 ` Simon Wright
2000-03-19  0:00 ` Robert Dewar
2000-03-20  0:00   ` Dale Stanbrough
2000-03-21  0:00     ` Robert Dewar

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