comp.lang.ada
 help / color / mirror / Atom feed
From: steve@anasazi.UUCP (Steve Villee)
Subject: Can CALENDAR.CLOCK be called during initialization?
Date: Thu, 8-May-86 00:09:40 EDT	[thread overview]
Date: Thu May  8 00:09:40 1986
Message-ID: <247@anasazi.UUCP> (raw)

Is the following package declaration legal, and guarranteed not to raise
PROGRAM_ERROR?

	with CALENDAR; pragma ELABORATE (CALENDAR);
	package FOO is

	   MOMENT : CALENDAR.TIME := CALENDAR.CLOCK;

	end FOO;

At first reading, section 10.5 of the LRM seems to suggest that it is safe to
call any subprogram during initialization (that is, during the elaboration of
a library package or its body), as long as you make sure the subprogram body
has been elaborated using pragma ELABORATE.  But after some thinking, I'm not
sure this is true.  It seems that a subprogram may or may not be "callable
during initialization", and that making it so requires cooperation from the
subprogram author, in general.  Consider the following code:

	function A return INTEGER;

	function B return INTEGER;

	with B; pragma ELABORATE (B);
	package C is

	   X : INTEGER := B;

	end C;

	with A;
	function B return INTEGER is
	begin
	   return A;
	end B;

	function A return INTEGER is
	begin
	   return 42;
	end A;

During the elaboration of package C, function B is called, and an attempt is
made to call function A.  It seems quite possible that this invocation of
function A might raise PROGRAM_ERROR if the body of A has not yet been
elaborated.  If function B were changed to include a "pragma ELABORATE (A);",
the problem would be solved.

Likewise, maybe CALENDAR.CLOCK calls some other subprogram and does not
use pragma ELABORATE, so it may be unsafe to call CALENDAR.CLOCK during
initialization.  Or am I missing something?  Is it a good general practice
to use pragma ELABORATE on everything you call, so as to make your subprogram
callable during initialization?

--- Steve Villee (ihnp4!terak!anasazi!steve)
    International Anasazi, Inc.
    7500 North Dreamy Draw Drive, Suite 120
    Phoenix, Arizona 85020
    (602) 870-3330

             reply	other threads:[~1986-05-08  4:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-05-08  4:09 Steve Villee [this message]
1986-05-14 15:18 ` Can CALENDAR.CLOCK be called during stt
1986-05-15 13:10 ` callen
replies disabled

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