comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
To: Chris Papademetrious <st92j0gw@dunx1.ocs.drexel.edu>
Subject: Re: types in procedure arguments
Date: 1996/09/30
Date: 1996-09-30T00:00:00+00:00	[thread overview]
Message-ID: <3250227D.4B43@watson.ibm.com> (raw)
In-Reply-To: 52nj8q$4ck@noc2.drexel.edu


Chris Papademetrious wrote:

>  I want to pass the type LIST_ID to a procedure I've defined.  The
> problem is that I've defined the type LIST_ID twice:
> 
>  1. at the beginning of the level where I call this procedure
>  2. in the package that holds the procedure itself, so I can use the
> type LIST_ID as a procedure argument
> 
>  The problem here is that each of these originates a new and unique
> "type LIST_ID" which aren't compatible with each other.  Thus, the
> calling statement that passes a type (1) of LIST_ID does not match the
> type (2) LIST_ID of the argument in the procedure being called!
> 
>  This seems basic, the idea of calling a subprogram with a type, and
> needing to define the type in a package so the subprogram can be
> declared.  How is this handled in Ada 95???  I'd be more than happy to
> provide a small test program, if anyone could lend me a hand.  I've
> been battling this for two weeks, and no books have been of any help.

The terminology you are using ("the level where I call this procedure",
"use the type LIST_ID as a procedure argument", "calling statement that
passes a type", "calling a subprogram with a type") does not make any
sense in Ada terms, so I can only guess what you mean.  You can pass a
type to a generic template to create an instance of that template; you
can pass a parameter OF a given type to a procedure.  Even though your
original query mentioned generic units, my best guess is that what you
are concerned with is passing a an object OF a given type to a
subprogram. 

If you want one compilation unit to declare a subprogram, another to
call the subprogram, and a third to declare the type used for one of the
parameters, the first two compilation units can be given a with clause
naming the third one.  For example:

   package Parameter_Types is
      type Parameter_Type is ...;
   end Parameter_Types;

   with Parameter_Types; use Parameter_Types;
   procedure Callee (Formal_Parameter: in Parameter_Type) is
      ...
   begin
      ...
   end Callee;

   with Parameter_Types, Callee; use Parameter_Types;
   procedure Caller is
      Actual_Parameter: Parameter_Type;
      ...
   begin
      Callee (Actual_Parameter);
      ...
   end Caller;

The first of these three units could just as easily have been the
instantiation of a generic package:

   with Generic_Template;
   package Parameter_Types is new Generic_Template ( ... );

Does this answer your question?

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




  reply	other threads:[~1996-09-30  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-28  0:00 types in procedure arguments Robert Dewar
1996-09-30  0:00 ` Chris Papademetrious
1996-09-30  0:00   ` Norman H. Cohen [this message]
1996-09-30  0:00   ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
1996-09-23  0:00 Chris Papademetrious
1996-09-25  0:00 ` Stephen Leake
1996-09-28  0:00 ` Chris Papademetrious
1996-09-28  0:00 ` Chris Papademetrious
1996-09-30  0:00 ` Chris Papademetrious
1996-10-01  0:00   ` Robert A Duff
1996-10-01  0:00   ` Norman H. Cohen
1996-10-01  0:00   ` Robert Dewar
1996-10-01  0:00   ` Stephen Leake
replies disabled

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