comp.lang.ada
 help / color / mirror / Atom feed
From: rational.com!geneo@uunet.uu.net  (Gene Ouye)
Subject: Re: Elaboration and parameters
Date: 29 Jun 93 21:06:26 GMT	[thread overview]
Message-ID: <1993Jun29.210626.22463@rational.com> (raw)

Risto Kaivola (rkaivola@mits.mdata.fi) wrote:
:   Consider the following Ada program:

: --------------
: --
: -- The purpose of this program is test exactly when PROGRAM_ERROR is
: -- raised if the body of a subprogram has not yet been elaborated.
: --

: with TEXT_IO; use TEXT_IO;

: procedure PROC is
:   MY_EXCEPTION : exception;

:   subtype S is INTEGER range 0 .. 1;
:   A : S;

:   function EXCEPT(ARG : S) return S is
:   begin
:     raise MY_EXCEPTION;
:     return S(0);
:   end EXCEPT;

:   procedure CURIOUS(ARG : S) is separate;

: begin
:   CURIOUS(EXCEPT(A));
: exception
:   when MY_EXCEPTION =>
:     PUT("E");
:   when PROGRAM_ERROR =>
:     PUT("NE");
: end PROC;

: ------------

: So, are the parameters of a subprogram evaluated if a body has
: not been provided?  In my opinion, the Ada83 LRM is not exactly
: clear on this.

Are you asking what will happen if you try to execute the above
code without the corresponding subunit for the procedure CURIOUS?
If so, you should not get Program_Error because the program should
not be linked without the subunit.  To do so would violate LRM 10.2(4).

If you want to raise Program_Error, try the following:

  procedure I_Wont_Elaborate; -- this spec will elaborate, but the body won't

  package A_Package is
      procedure Some_Procedure_That_Wont_Get_Called;
  end A_Package;

  with A_Package;
  procedure I_Wont_Elaborate is
  begin
      A_Package.Some_Procedure_That_Wont_Get_Called;
  end I_Wont_Elaborate;

  with I_Wont_Elaborate;
  package body A_Package is
      procedure Some_Procedure_That_Wont_Get_Called is
      begin
          null; -- it doesn't matter here, we won't get called
      end Some_Procedure_That_Wont_Get_Called;
  begin
      I_Wont_Elaborate; -- an appropriate call...
  end A_Package;


I make no claims as to the invalidity of this code, I just typed it in
off the top of my head.  I'm sure others can come up with more succinct
examples (but that's not an invitation for a new thread!-)

Have fun with this,
Gene Ouye (geneo@rational.com)

(301) 897-4014

             reply	other threads:[~1993-06-29 21:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-06-29 21:06 Gene Ouye [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-07-04 16:49 Elaboration and parameters Simon Wright
1993-07-02  7:00 Richard A. O'Keefe
1993-06-29 23:20 Risto Kaivola
1993-06-29 19:51 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne
replies disabled

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