comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@dsd.camb.inmet.com (Bob Duff)
Subject: Re: pragma ELABORATE not allowed (Sun Ada)
Date: Tue, 18 Oct 1994 14:32:05 GMT
Date: 1994-10-18T14:32:05+00:00	[thread overview]
Message-ID: <CxvHpH.24K@inmet.camb.inmet.com> (raw)
In-Reply-To: CxvC8G.7sw@trh.cap-computas.no

In article <CxvC8G.7sw@trh.cap-computas.no>,
Ulf Stenhaug <ust@trh.cap-computas.no> wrote:
>package body configure is
...
>end configure;
>
>with configure;
>package rename_config is
...
>end rename_config;
...
>with rename_config;
>with other_packages_which_also_use_configure;
>program main is
 ^^^^^^^ You mean "procedure" or "package body" here.
If it's a procedure (the main subprogram), then there should be no
problem, since everything is elaborated before the main subprogram is
called.  So I assume this is really a package.

Elaboration order is different on different implementations (within some
constraints).  So it's not surprising that the code happened to work on
one compiler, and you got Program_Error on the other one.

>Now to the real problem: We insert "pragma ELABORATE(rename_config)"
>after the with-statement, but then the compiler refers to ARM
>appendix B and complains that
>  "This pragma not allowed in this context."
>
>Why is it not allowed? What can we do??????

In Ada 83, you have to put all the pragmas Elaborate *after* all of the
with_clauses and use_clauses.  This restriction has been removed in Ada
9X.

You really need to elaborate the body of Configure (not just
Rename_Configure) before the body of package Main.  This means you need
to say pragma Elaborate(Configure).  But in order to do that, you have
to add "with Configure;".  That's a real pain, because Main doesn't
reference anything in Configure, and so shouldn't have to mention it in
a with_clause.  This is a flaw in the language design.

This problem has also been solved in Ada 9X.  In Ada 9X, you can say
pragma Elaborate_All(Rename_Configure).  This is just like pragma
Elaborate, except that it automatically applies to everything the spec
and body of Rename_Configure depends on.  In Ada 9X, you should always
use pragma Elaborate_All instead of Elaborate, except in certain rare
circumstances involving mutually recursive packages, where Elaborate_All
would cause a circularity.

Ada 9X also has some other pragmas for controlling elaboration.  Pragma
Preelaborate (and pragma Pure) cause the package spec and body to be
elaborated "first" (before non-preelaborated things).  Pragma
Elaborate_Body, means don't elaborate anything in between the spec and
body of this package.  All of these reduce your chances of getting
Program_Error because you called something before it was elaborated.
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)



      reply	other threads:[~1994-10-18 14:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-18 12:33 pragma ELABORATE not allowed (Sun Ada) Ulf Stenhaug
1994-10-18 14:32 ` Bob Duff [this message]
replies disabled

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