From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,62a0e3de4e2ff2c7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-19 16:02:35 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!spool.mu.edu!bloom-beacon.mit.edu!panix!cmcl2!thecourier.cims.nyu.edu!thecourier.cims.nyu.edu!nobody From: dewar@cs.nyu.edu (Robert Dewar) Newsgroups: comp.lang.ada Subject: Re: Tagged type: how to know which specific type Date: 19 Mar 1995 17:27:23 -0500 Organization: Courant Institute of Mathematical Sciences Message-ID: <3kib4b$igt@gnat.cs.nyu.edu> References: NNTP-Posting-Host: gnat.cs.nyu.edu Date: 1995-03-19T17:27:23-05:00 List-Id: 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!