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

* Re: Can CALENDAR.CLOCK be called during
  1986-05-08  4:09 Can CALENDAR.CLOCK be called during initialization? Steve Villee
@ 1986-05-14 15:18 ` stt
  1986-05-15 13:10 ` callen
  1 sibling, 0 replies; 3+ messages in thread
From: stt @ 1986-05-14 15:18 UTC (permalink / raw)



You have run into the basic flaw with Pragma ELABORATE.
Its usefulness is severely limited given its current
semantics.  It would be much more useful
if a pragma ELABORATE of a unit implied a pragma ELABORATE
of all of the units its body "with"s.  Ada '88?

Nevertheless, most compilers implement "friendly"
elaboration order so you won't necessarily run
into the problems.  It turns out that the ACVC's
made the same assumption, that pragma elaborating
package Report was sufficient to avoid PROGRAM_ERROR.
In fact, Report "with"s Text-IO, so it is quite possible
that a call on Report during elaboration will die
somewhere in Text-IO with PROGRAM_ERROR.

The newest ACVC suite includes a pragma ELABORATE(Text_IO);
on the report package body.

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

* Re: Can CALENDAR.CLOCK be called during
  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
  1 sibling, 0 replies; 3+ messages in thread
From: callen @ 1986-05-15 13:10 UTC (permalink / raw)



This is, of course, not really an answer (stt furnished THAT), but
I tried your particular program on my favorite Ada compiler (the
Intermetrics MVS Ada compiler) and it worked.

This proves nothing, except the willingness of certain programmers
(ME) to feed source code to their compiler and see what happens :-)

-- Jerry Callen      ...(ima,ihnp4)!inmet!ada-uts!callen

^ 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