comp.lang.ada
 help / color / mirror / Atom feed
* pragma Elaborate (Comp. Unit) question.
@ 1999-05-21  0:00 Michael
  1999-05-22  0:00 ` Thierry Lelegard
  0 siblings, 1 reply; 5+ messages in thread
From: Michael @ 1999-05-21  0:00 UTC (permalink / raw)


Hi All,

  2 questions:

  Should one ever *need* get an error message from a compiler that a
compilation unit needs to have a "pragma Elaborate" clause for another
unit?

  That is, if the compiler knows what the elaboration order needs to be
why can't it make the relavant deterministic change and proceed with a
warning?

  Is it because elaboratation is by definition non-deterministic and if
so why is it that way?

 FYI, I am using Vads Ada83.

-- Michael

Take out the "no_" and the "_spam" to reply




^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: pragma Elaborate (Comp. Unit) question.
@ 1999-05-24  0:00 Robert I. Eachus
  1999-05-25  0:00 ` Robert Dewar
  0 siblings, 1 reply; 5+ messages in thread
From: Robert I. Eachus @ 1999-05-24  0:00 UTC (permalink / raw)



>   Should one ever *need* get an error message from a compiler that a
> compilation unit needs to have a "pragma Elaborate" clause for another
> unit?
> 
>   That is, if the compiler knows what the elaboration order needs to be
> why can't it make the relavant deterministic change and proceed with a
> warning?

    There is a very deep answer lurking here...  For most programs,
there exists an order of elaboration that can be discovered at compile
time and will never cause Program_Error to be raised.  Good compilers
will try to choose a workable order but for some programs, finding that
order is extremely hard in a computability sense.  I once wrote an
example of this where the "correct' order of elaboration depended on
whether or not Fermat's Last Theorem was true.  (Now that compilers can
get that one right, I'll have to come up with a different example. ;-)

    But it gets worse.  It is relatively trivial to write a program
where data input from the keyboard at run-time determines whether or not
a particular elaboration order works.  (I've seen Comp Sci 101 students
write such programs--without inteding to. ;-)  It is a little trickier,
but not much, to create a program where there are several possible
elaboration orders at compile time, and for each one there are inputs
that cause Program_Error, and others that don't.

    This is why pragma Elaborate, and in Ada 95, pragmas Elaborate_All
and Elaborate_Body, are there.  If the "correct" elaboration order for
your program depends on Fermat's Last Theorem, you can tell the compiler
what to do instead of relying on the compiler's built in theorem prover.

    Now back to the compile time error message.  This message is trying
to tell you that the compiler couldn't find a workable elaboration
order, but maybe if you give it a hint...  Of course, you often get the
message when the elaboration order is already overconstrained and what
you really need to do is to figure out how to remove some of the
dependencies.  The compiler is trying to be helpful and give you a clue
as to where the problem is, but usually if you get that message, finding
a workable order is hard.  (See above.)  Better is to restructure your
program so that it is easy.  This often involves spliting packages or
moving some initialization code into the main program.


                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




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

end of thread, other threads:[~1999-05-25  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-21  0:00 pragma Elaborate (Comp. Unit) question Michael
1999-05-22  0:00 ` Thierry Lelegard
1999-05-22  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1999-05-24  0:00 Robert I. Eachus
1999-05-25  0:00 ` Robert Dewar

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