comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
Subject: Exchanging objects between programs with different inheritance hierarchies
Date: Tue, 12 Nov 2002 20:19:52 -0600
Date: 2002-11-12T20:19:52-06:00	[thread overview]
Message-ID: <mailman.1037153942.12692.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3DC93287.2EA290F0@myob.com>

Ada experts,
We are in the process of trying to convert some code to GNAT that worked
on another Ada compiler.   The code transmits tagged type objects
between processes, and uses unchecked conversion at the receiving end to
convert to the destination object type.  The objects are various types
derived from a "base" object with identical inheritance "path", but not
identical inheritance hierarchies.  

Using unchecked_conversion depends on the tags being integral to the
record structures.  On GNAT they are not, so the code fails.

The code is clearly incorrect Ada.  

My question is, what this a reliable, portable way to do that transfer.
The "solution" should only involve reasoning from the Ada RM, not any
detailed knowledge of any compiler, including GNAT.

I believe streams and 'Class'Output and 'Class'Input may be the answer,
but find myself unable to fully understand the RM's "contract" with
regard to writing, and then reading, tagged type objects.

I assume 'Class'Input will correctly work when the same *process*
performed the 'Class'Output.

What about the same *program* running as one *process* doing the
'Class'Output and as another *process* of the same program doing the
'Class'Input? (That is, is an Ada compiler allowed to build tag
information at elaboration time, with possible variations from run to
run?)

What about different programs, but with the identical inheritance
hierarchy for the types in question? (There might be other differing
type hierarchies, but not for the types being transmitted.)

Finally, the 64K question.  What if the inheritance hierarchies differ,
but transmission is limited to types that have the identical inheritance
"path" within the hierarchy?

For a specific example, assume the following hierarchy in program X
   Top ( A (aa,ab), B (ba,bb) )

and the following in program Y
   Top( A (aa,ac), B (bb), C(ca,cb) )

i.e. aa is derived from A and A from Top in both programs, using
identical type names and identical type definitions (from the same
sources, but not necessarily compiled on the same system.)

If X uses Top'Class'Output to write an object of type Top.A.aa and Y
uses Top'Class'Input to read the object, will Y have a valid Top.A.aa in
Y with the same data values as were in X?

If X outputs Top.A.ab, what happens in Y when it tries a 'Class'Input?
(Constraint_Error?, erroneous program with bounded error? something
else?).

One last question, which does not affect this particular effort, but
could affect future work.  What if the inheritance hierarchies are
identical in structure, but not in the particular names used for the
various types and components.  Is there anything in 'Class'Output/Input
that would permit exchanging those structurally-equivalent and
inheritance-equivalent types?

Regards,
Steven Deller




       reply	other threads:[~2002-11-13  2:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3DC93287.2EA290F0@myob.com>
2002-11-13  2:19 ` Steven Deller [this message]
2002-11-13  6:05   ` Exchanging objects between programs with different inheritance hierarchies Jim Rogers
2002-11-13 15:54     ` Simon Wright
2002-11-13 17:44       ` tmoran
2002-11-14  6:29         ` Simon Wright
2002-11-13 17:59   ` Jeffrey Carter
2002-11-13 18:23     ` Robert A Duff
2002-11-13 23:17       ` Steven Deller
2002-11-13 12:18 Grein, Christoph
     [not found] <200211131218.NAA13957@bulgaria.otn.eurocopter.de>
2002-11-13 17:22 ` Steven Deller
2002-11-13 18:12   ` Robert A Duff
replies disabled

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