comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@gnat.com>
Subject: Re: static objects in ADA
Date: 1999/04/25
Date: 1999-04-25T00:00:00+00:00	[thread overview]
Message-ID: <7fv781$60e$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 4IaN6CA84vI3EwTh@tioman.demon.co.uk

In article <4IaN6CA84vI3EwTh@tioman.demon.co.uk>,
  Mark Elson <marke@tioman.demon.co.uk> wrote:
> I slipped up here in my terminology - whilst I was
> thinking of static initialisation being at compile/link
> time the relevant C++ keyword is
> actually const. What prompted me to think of this
> approach is the common
> use of const character arrays to store config control
> info as strings in
> object files.

As far as I know, there is no requirement in C++ that
const objects be initialized at link time. Such a
requirement is pretty hard to state, since at the level
of a semantic definition, such a distinction has no
semantically observable effects.

In practice, C++ compilers very reasonably do what you
expect ...

In the case of Ada, pragma Preealborate is intended to
have much the same effect, but here to, it is impossible
to guarantee that you get link time initialization, since
this is hard to talk about, and the best we can do in Ada
is the following "requirement":

  3   The implementation shall not execute any memory write
      operations after load time for the elaboration of
      constant objects declared immediately within
      the declarative region of a preelaborated library
      package, so long as the subtype and initial
      expression (or default initial expressions if
      initialized by default) of the object_declaration
      satisfy the following restrictions. The meaning of
      load time is implementation defined.

The "implementation defined" at the end is of course a
worry, but it is unavoidable, any attempt to formally
define load time would fail.

In practice, if you write

     type x is array (0 .. 100_000_000) of boolean;
     vx : x := (others => False);

I would guess many implementations would output object
code that would expand this as part of loading on a system
where to do otherwise would generate a gigantic 100 meg or
bigger load module.

In GNAT we have provided the additional restrictions
identifier:

  pragma Restrictions (No_Elaboration_Code);

which really means what it says, and if you use this, you
can be sure that you have NO code at all for runtime
elaboration.

Here is the restrictions pragma in action:

     1. pragma Restrictions (No_Elaboration_Code);
     2. package q is
     3.      type x is array (0 .. 100_000_000) of boolean;
     4.      vx : x := (others => False);
                       |
        >>> violation of restriction "no_elaboration_code"
            at line 1

     5. end q;

If you change the range of the array to something more
reasonable, the message will go away, since the compiler
will be willing to initialize small arrays at link time.

Again, the best advice is contact your vendor, the trouble
with general posts on CLA is that they tend to go in the
wrong direction sometimes :-)

Everyone assumed you were talking about the static scope
issue, when in fact your concern about load time
initialization for safety critical programs was a
completely different one.


Robert Dewar
Ada Core Technologies



-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  reply	other threads:[~1999-04-25  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-21  0:00 static objects in ADA Mark Elson
1999-04-21  0:00 ` Marin David Condic
1999-04-21  0:00 ` dennison
1999-04-21  0:00 ` Stephen Leake
1999-04-22  0:00 ` Samuel Mize
1999-04-25  0:00   ` Mark Elson
1999-04-25  0:00     ` Robert Dewar [this message]
1999-04-26  0:00     ` dennison
1999-04-26  0:00       ` Robert Dewar
1999-05-07  0:00     ` Mark Elson
1999-05-07  0:00       ` dennison
1999-04-25  0:00 ` Matthew Heaney
replies disabled

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