comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <eachus@mitre.org>
Subject: Re: pragma Elaborate (Comp. Unit) question.
Date: 1999/05/24
Date: 1999-05-24T00:00:00+00:00	[thread overview]
Message-ID: <3749F3B9.202F7A13@mitre.org> (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...




             reply	other threads:[~1999-05-24  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-05-24  0:00 Robert I. Eachus [this message]
1999-05-25  0:00 ` pragma Elaborate (Comp. Unit) question Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1999-05-21  0:00 Michael
1999-05-22  0:00 ` Thierry Lelegard
1999-05-22  0:00   ` Robert Dewar
replies disabled

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