[net.lang.ada] Can CALENDAR.CLOCK be called during initialization?

steve@anasazi.UUCP (Steve Villee) (05/08/86)

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