comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Tagged type: how to know which specific type
Date: 19 Mar 1995 17:27:23 -0500
Date: 1995-03-19T17:27:23-05:00	[thread overview]
Message-ID: <3kib4b$igt@gnat.cs.nyu.edu> (raw)
In-Reply-To: WOODRUFF.95Mar18114334@tanana.llnl.gov

You can of course pass Tag values around, but you can't dispatch on them.
It is indeed true that if you want to dispatch you must send along at least
a dummy instance of the value. I have run into this in writing the file
stuff for GNAT (which is incidentally quite a nice example of the use of
tagged types -- each of the I/O modules, text_io, sequential_io etc uses
a control block derived by extension from an abstract common control block,
and then operations like open are class-wide operations, and there is a
dispatching operation for close called when files are closed automatically.

Well when I wrote open, the common code needs to call the dispatching
Allocate routine to allocate an instance of the control block. I found
that I had to declare a dummy instance of the control block to pass to the
open procedure so it knew which Allocate to call. It's a little annoying,
since at some level it would be fine to pass just the Tag, since in practice
that is a pointer to the dispatching table - oh well. It is not so terrible
to write:

    Dummy_Control_Block : Text_File_Control_Block;

    Open ( ......, Dummy_Control_Block, ....)

and I guess you have to do the same with your Gasoline and Printer example

    Fuel_Type : Gasolene;

    Print ( ...., Fuel_Type, ....)

again, not so terrible!




  reply	other threads:[~1995-03-19 22:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-18 19:43 Tagged type: how to know which specific type woodruff
1995-03-19 22:27 ` Robert Dewar [this message]
1995-03-21 14:38 ` Tucker Taft
replies disabled

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