comp.lang.ada
 help / color / mirror / Atom feed
* Can CALENDAR.CLOCK be called during initialization?
@ 1986-05-08  4:09 Steve Villee
  1986-05-14 15:18 ` Can CALENDAR.CLOCK be called during stt
  1986-05-15 13:10 ` callen
  0 siblings, 2 replies; 3+ messages in thread
From: Steve Villee @ 1986-05-08  4:09 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1986-05-15 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-05-08  4:09 Can CALENDAR.CLOCK be called during initialization? Steve Villee
1986-05-14 15:18 ` Can CALENDAR.CLOCK be called during stt
1986-05-15 13:10 ` callen

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