comp.lang.ada
 help / color / mirror / Atom feed
* Re: Access to strings and string subtypes?
@ 2000-03-17  0:00 Christoph Grein
  0 siblings, 0 replies; 12+ messages in thread
From: Christoph Grein @ 2000-03-17  0:00 UTC (permalink / raw)
  To: comp.lang.ada

package Test is

   type Ref is access all String;     <-- unconstrained

   subtype Name is String(1..10);     <-- constrained
   type Name_Ref is access all Name;

   A : aliased Name;                  <-- constrained
   C : aliased String (1..10);        <-- constrained

   D : Name_Ref := A'Access; -- OK
   E : Ref := A'Access; -- Does not statically match designated subtype ???
   F : Ref := C'Access; -- Does not statically match designated subtype ???

   G : Ref := new String'("THIS WORKS"); -- OK!

end Test;

The compiler message ("Does not statically match designated subtype") says
exactly what is wrong:

A pointer to an unconstrained string has to take care of the actual object's 
ranges, a pointer to a constrained string need not.

Thus A'Access and C'Access do not provide range information whereas
   new String'("THIS WORKS")
does.









^ permalink raw reply	[flat|nested] 12+ messages in thread
* Access to strings and string subtypes?
@ 2000-03-16  0:00 Steve Folly
  2000-03-16  0:00 ` Ehud Lamm
  0 siblings, 1 reply; 12+ messages in thread
From: Steve Folly @ 2000-03-16  0:00 UTC (permalink / raw)


Could someone explain why this code doesn't work.
I know the LRM reference that prevents it, but, in laymans terms, please explain
*why* :-)

package Test is

   type Ref is access all String;

   subtype Name is String(1..10);
   type Name_Ref is access all Name;

   A : aliased Name;
   C : aliased String (1..10);

   D : Name_Ref := A'Access; -- OK
   E : Ref := A'Access; -- Does not statically match designated subtype ???
   F : Ref := C'Access; -- Does not statically match designated subtype ???

   G : Ref := new String'("THIS WORKS"); -- OK!

end Test;


I would have expected a Ref type to be able to point to any constrained string
type. Why are subtypes not allowed?

We have various classes defined with strings of different sizes, but would like
a single function to be able to take any one of these strings and manipulate it,
possibly changing it's contents.


Thanks.

Steve Folly.





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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-17  0:00 Access to strings and string subtypes? Christoph Grein
  -- strict thread matches above, loose matches on Subject: below --
2000-03-16  0:00 Steve Folly
2000-03-16  0:00 ` Ehud Lamm
2000-03-16  0:00   ` Steve Folly
2000-03-17  0:00     ` Ehud Lamm
2000-03-17  0:00       ` Larry Kilgallen
2000-03-17  0:00         ` Robert Dewar
2000-03-17  0:00           ` Robert A Duff
2000-03-18  0:00             ` Robert Dewar
2000-03-20  0:00               ` Tucker Taft
2000-03-17  0:00       ` Steve Folly
2000-03-17  0:00         ` Pascal Obry

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