comp.lang.ada
 help / color / mirror / Atom feed
* Subtypes do not Statically Match
@ 1999-06-30  0:00 John Harbaugh
  1999-06-30  0:00 ` James S. Rogers
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: John Harbaugh @ 1999-06-30  0:00 UTC (permalink / raw)


Hi all -

Suppose I have a record with an unconstrained array component which is
constrained by the record discriminant.  Now I want to pass a record
pointer (oops! access value) to a function which will return a pointer
to the array component:


package Parent is

   type Object(Max : Positive) is tagged record
      Component : aliased String(1..Max);
   end record;
   
   type String_Ref is access all String;
 
   function The_Handle(Obj : access Object) return String_Ref;
end;

package body Parent is

   function The_Handle(Obj : access Object) return String_Ref is
   begin
      return Obj.Component'access;
      --Error: object subtype must statically match designated subtype
   end;
   
end;


Apparently, the problem is that the range constraint on the component
creates an anonymous subtype of string that is not subtype conferment
with type String.  In other circumstances, we would declare a
constrained subtype for the component and the return type.  In this case
we really do want variable sized string - some might be a few
characters, and others may be millions of characters.  Any suggestions
on how to write the function body?

BTW, this works if we pass in an object to the function rather than an
access value.  But if we want to process a heterogeneous list of objects
from the class, we need to use pointers.

Best regards,

	- John Harbaugh




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

end of thread, other threads:[~1999-07-02  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-30  0:00 Subtypes do not Statically Match John Harbaugh
1999-06-30  0:00 ` James S. Rogers
1999-07-01  0:00   ` John Harbaugh
1999-07-02  0:00     ` Robert I. Eachus
1999-07-01  0:00 ` Robert A Duff
1999-07-01  0:00 ` Gautier
1999-07-01  0:00   ` John Harbaugh
1999-07-01  0:00 ` Ted Dennison

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