comp.lang.ada
 help / color / mirror / Atom feed
* Initialized global data
@ 1998-05-05  0:00 Kevin Wells
  1998-05-05  0:00 ` A little more data Kevin Wells
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Kevin Wells @ 1998-05-05  0:00 UTC (permalink / raw)



When specifying data in an Ada package that is pre-initialized such as
----------------------------------------
package Generate_Matrix is
  Scale_Factor : float := 10.903;
  .
end Generate_Matrix; -- spec
----------------------------------------

1. Is it normal for the compiler to generate code that sets the value in
memory
    (that gets executed when the runtime system is initialized)?
2. Is there a way to get around this?

I am trying to create pre-initialized data arrays in memory such as
----------------------------------------
type Array_Type is array (1 .. 5) of integer;
Small_Array : Array_Type := (1, 10, 5, 9, -50);
----------------------------------------
but the compiler generates a bunch of code to set those 5 memory
locations.
(The actual code generated is about 3 to 5 times the size of the data
area
of the array). This really isn't a problem, except we only have a 64K
machine
with about 48K of it being used already. To make matters worse, a
reserve
of about 25% must be maintained for future changes. (That leaves me with

about 0 words of memory to add things :) ) I have about 3100 words of
data that is initialized at compile time.

I have been coding for about 7-1/2 years now. The first 5-1/2 developing
C
and assembly applications..only the last 2 have been in Ada. I feel I
know Ada
pretty good (and I really appreciate the 'control' it gives me in
developing
safe and tolerant code over other langauges). However, I'm not too sure
about how to handle this - In C, a seperate 'pre-initialized data
segment was
kept separately (along with other segments).

Does anyone have any ideas or suggestions about doing this that fits
within
Ada's elegant realm of development (No external overlays) and allows the

actual preinitialized data (without the code) to be saved in the final
executable?

Thanks much,
Kevin Wells, Software Engineer, Boeing
wellsk@netcom.com





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

* A little more data
  1998-05-05  0:00 Initialized global data Kevin Wells
@ 1998-05-05  0:00 ` Kevin Wells
  1998-05-06  0:00   ` Stephen Leake
  1998-05-06  0:00 ` Initialized global data Anonymous
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Kevin Wells @ 1998-05-05  0:00 UTC (permalink / raw)



BTW - I'm using the EDS Ada compiler targeted for a 1750A processor
hosted on a DEC Alpha platform. If anyone needs any code snippets to
help me out, let me know...

Thanks again,
Kevin Wells

Kevin Wells wrote:

> When specifying data in an Ada package that is pre-initialized such as
> ----------------------------------------
> package Generate_Matrix is
>   Scale_Factor : float := 10.903;
>   .
> end Generate_Matrix; -- spec
> ----------------------------------------
>
> 1. Is it normal for the compiler to generate code that sets the value in
> memory
>     (that gets executed when the runtime system is initialized)?
> 2. Is there a way to get around this?
>
> I am trying to create pre-initialized data arrays in memory such as
> ----------------------------------------
> type Array_Type is array (1 .. 5) of integer;
> Small_Array : Array_Type := (1, 10, 5, 9, -50);
> ----------------------------------------
> but the compiler generates a bunch of code to set those 5 memory
> locations.
> (The actual code generated is about 3 to 5 times the size of the data
> area
> of the array). This really isn't a problem, except we only have a 64K
> machine
> with about 48K of it being used already. To make matters worse, a
> reserve
> of about 25% must be maintained for future changes. (That leaves me with
>
> about 0 words of memory to add things :) ) I have about 3100 words of
> data that is initialized at compile time.
>
> I have been coding for about 7-1/2 years now. The first 5-1/2 developing
> C
> and assembly applications..only the last 2 have been in Ada. I feel I
> know Ada
> pretty good (and I really appreciate the 'control' it gives me in
> developing
> safe and tolerant code over other langauges). However, I'm not too sure
> about how to handle this - In C, a seperate 'pre-initialized data
> segment was
> kept separately (along with other segments).
>
> Does anyone have any ideas or suggestions about doing this that fits
> within
> Ada's elegant realm of development (No external overlays) and allows the
>
> actual preinitialized data (without the code) to be saved in the final
> executable?
>
> Thanks much,
> Kevin Wells, Software Engineer, Boeing
> wellsk@netcom.com







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

* Re: A little more data
  1998-05-05  0:00 ` A little more data Kevin Wells
@ 1998-05-06  0:00   ` Stephen Leake
  0 siblings, 0 replies; 13+ messages in thread
From: Stephen Leake @ 1998-05-06  0:00 UTC (permalink / raw)



If this is an Ada 95 compiler (which I doubt, given the target), try
Pragma Preelaborate.

In Ada 83, there may be a compiler switch to cause pre-elaboration.

Or, if you can live with constant data, try declaring Scale_Factor to be
"constant".

-- Stephe

Kevin Wells wrote:
> 
> BTW - I'm using the EDS Ada compiler targeted for a 1750A processor
> hosted on a DEC Alpha platform. If anyone needs any code snippets to
> help me out, let me know...
> 
> Thanks again,
> Kevin Wells
> 
> Kevin Wells wrote:
> 
> > When specifying data in an Ada package that is pre-initialized such as
> > ----------------------------------------
> > package Generate_Matrix is
> >   Scale_Factor : float := 10.903;
> >   .
> > end Generate_Matrix; -- spec
> > ----------------------------------------
> >
> > 1. Is it normal for the compiler to generate code that sets the value in
> > memory
> >     (that gets executed when the runtime system is initialized)?
> > 2. Is there a way to get around this?
> >
> > I am trying to create pre-initialized data arrays in memory such as
> > ----------------------------------------
> > type Array_Type is array (1 .. 5) of integer;
> > Small_Array : Array_Type := (1, 10, 5, 9, -50);
> > ----------------------------------------
> > but the compiler generates a bunch of code to set those 5 memory
> > locations.
> > (The actual code generated is about 3 to 5 times the size of the data
> > area
> > of the array). This really isn't a problem, except we only have a 64K
> > machine
> > with about 48K of it being used already. To make matters worse, a
> > reserve
> > of about 25% must be maintained for future changes. (That leaves me with
> >
> > about 0 words of memory to add things :) ) I have about 3100 words of
> > data that is initialized at compile time.
> >
> > I have been coding for about 7-1/2 years now. The first 5-1/2 developing
> > C
> > and assembly applications..only the last 2 have been in Ada. I feel I
> > know Ada
> > pretty good (and I really appreciate the 'control' it gives me in
> > developing
> > safe and tolerant code over other langauges). However, I'm not too sure
> > about how to handle this - In C, a seperate 'pre-initialized data
> > segment was
> > kept separately (along with other segments).
> >
> > Does anyone have any ideas or suggestions about doing this that fits
> > within
> > Ada's elegant realm of development (No external overlays) and allows the
> >
> > actual preinitialized data (without the code) to be saved in the final
> > executable?
> >
> > Thanks much,
> > Kevin Wells, Software Engineer, Boeing
> > wellsk@netcom.com




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

* Re: Initialized global data
  1998-05-05  0:00 Initialized global data Kevin Wells
                   ` (2 preceding siblings ...)
  1998-05-06  0:00 ` John English
@ 1998-05-06  0:00 ` Tucker Taft
  1998-05-09  0:00 ` Niklas Holsti
  4 siblings, 0 replies; 13+ messages in thread
From: Tucker Taft @ 1998-05-06  0:00 UTC (permalink / raw)



Kevin Wells (wellsk@worldnet.att.net) wrote:

: When specifying data in an Ada package that is pre-initialized such as
: ----------------------------------------
: package Generate_Matrix is
:   Scale_Factor : float := 10.903;
:   .
: end Generate_Matrix; -- spec
: ----------------------------------------

: 1. Is it normal for the compiler to generate code that sets the value in
: memory
:     (that gets executed when the runtime system is initialized)?

That of course depends on the implementation.  I would say
that most "good" implementations support static initialization
of variables like the one above.  If the initial value is non-static,
then of course run-time code is required.

: 2. Is there a way to get around this?

Choose a different implementation.  What are the host and target
of interest?  I suspect comp.lang.ada readers could inform you
of compilers that do what you want.

: I am trying to create pre-initialized data arrays in memory such as
: ----------------------------------------
: type Array_Type is array (1 .. 5) of integer;
: Small_Array : Array_Type := (1, 10, 5, 9, -50);
: ----------------------------------------
: but the compiler generates a bunch of code to set those 5 memory
: locations.
: (The actual code generated is about 3 to 5 times the size of the data
: area
: of the array). 
: ...
: Does anyone have any ideas or suggestions about doing this that fits
: within
: Ada's elegant realm of development (No external overlays) and allows the

: actual preinitialized data (without the code) to be saved in the final
: executable?

As mentioned above, it would be useful to know the host and target.
Also, it would be important to see the exact code being used.
If the upper bound of the array is dynamic, or if this table
is in the main subprogram rather than in a package, you might
end up with the problem you are seeing, even with a "good" implementation.

One thing that will certainly help increase the likelihood of
static initialization is to use "constant Array_Type" rather than
simply "Array_Type" if the array is not being altered after initialization.

: Thanks much,
: Kevin Wells, Software Engineer, Boeing
: wellsk@netcom.com

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




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

* Re: Initialized global data
  1998-05-05  0:00 Initialized global data Kevin Wells
  1998-05-05  0:00 ` A little more data Kevin Wells
@ 1998-05-06  0:00 ` Anonymous
  1998-05-08  0:00   ` Simon Wright
  1998-05-06  0:00 ` John English
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Anonymous @ 1998-05-06  0:00 UTC (permalink / raw)



On Tue, 05 May 1998 22:24:45 -0700, Kevin Wells
<wellsk@worldnet.att.net> wrote:

> When specifying data in an Ada package that is pre-initialized such as
> ----------------------------------------
> package Generate_Matrix is
>   Scale_Factor : float := 10.903;
>   .
> end Generate_Matrix; -- spec
> ----------------------------------------
> 
> 1. Is it normal for the compiler to generate code that sets the value in
> memory
>     (that gets executed when the runtime system is initialized)?

Yes.

> 2. Is there a way to get around this?

You might try pragma Preelaborate (Ada only; not available in Ada 83).

> 
> I am trying to create pre-initialized data arrays in memory such as
> ----------------------------------------
> type Array_Type is array (1 .. 5) of integer;
> Small_Array : Array_Type := (1, 10, 5, 9, -50);
> ----------------------------------------
> but the compiler generates a bunch of code to set those 5 memory
> locations.
> ...

The general rule for global variables is: Never use global variables.

If these are not actually variables, they should be constants:

Scale_Factor : constant := 10.903; -- OR ": constant Float :="

Small_Array : constant Array_Type := (1, 10, 5, 9, -50);

In the case of named numbers (X : constant := 7.3;), the compiler should
not generate any code or allocate any memory. In the case of typed
constants (X : constant T := V;), both may occur. Pragma Preelaborate
might take care of this for you.

If the numbers are in ROM, you have to be able to get around this. You
might be able to use a deferred constant with a pragma Import (Ada
only):

X : constant T;
pragma Import (Convention, X, "Name_Of_X");

Ask your compiler vendor.

Or you can use an uninitialized "variable" (that doesn't) at a specified
address:

X : T;
for X'Address use A; -- Ada 83: "for X use at A;"

The compiler might then warn you that you are accessing undefined
values, but you know you can ignore these warnings.

Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"I waggle my private parts at your aunties."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




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

* Re: Initialized global data
  1998-05-05  0:00 Initialized global data Kevin Wells
  1998-05-05  0:00 ` A little more data Kevin Wells
  1998-05-06  0:00 ` Initialized global data Anonymous
@ 1998-05-06  0:00 ` John English
  1998-05-06  0:00 ` Tucker Taft
  1998-05-09  0:00 ` Niklas Holsti
  4 siblings, 0 replies; 13+ messages in thread
From: John English @ 1998-05-06  0:00 UTC (permalink / raw)



Kevin Wells (wellsk@worldnet.att.net) wrote:
: 1. Is it normal for the compiler to generate code that sets the value in
: memory (that gets executed when the runtime system is initialized)?
: 2. Is there a way to get around this?

Does the same thing happen if you declare constants rather than
variables? Certainly I know of a C compiler that used to generate
code to initialise variables but just stored an image of constant
values...

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




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

* Re: Initialized global data
  1998-05-06  0:00 ` Initialized global data Anonymous
@ 1998-05-08  0:00   ` Simon Wright
  1998-05-08  0:00     ` Tucker Taft
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Wright @ 1998-05-08  0:00 UTC (permalink / raw)



nobody@REPLAY.COM (Anonymous) writes:
[...]
> Or you can use an uninitialized "variable" (that doesn't) at a specified
> address:
> 
> X : T;
> for X'Address use A; -- Ada 83: "for X use at A;"

I'm not sure of chapter-and-verse, but I believe that a compiler is
allowed to initialize X here under some circumstances; which wouldn't
be what you wanted!

The specific case where this happened to us was when T happened to be
a packed array of bits. We were assured by our support that it was OK
for their compiler to initialize all the bits to 0, I was dubious
about this! (and I can't seem to recreate the situation in the latest
release ..)




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

* Re: Initialized global data
  1998-05-08  0:00   ` Simon Wright
@ 1998-05-08  0:00     ` Tucker Taft
  1998-05-09  0:00       ` Simon Wright
  0 siblings, 1 reply; 13+ messages in thread
From: Tucker Taft @ 1998-05-08  0:00 UTC (permalink / raw)



Simon Wright (simon@pogner.demon.co.uk) wrote:

: nobody@REPLAY.COM (Anonymous) writes:
: [...]
: > Or you can use an uninitialized "variable" (that doesn't) at a specified
: > address:
: > 
: > X : T;
: > for X'Address use A; -- Ada 83: "for X use at A;"

: I'm not sure of chapter-and-verse, but I believe that a compiler is
: allowed to initialize X here under some circumstances; which wouldn't
: be what you wanted!

A "pragma Import(Ada, X);" would prevent initialization.

: The specific case where this happened to us was when T happened to be
: a packed array of bits. We were assured by our support that it was OK
: for their compiler to initialize all the bits to 0, I was dubious
: about this! (and I can't seem to recreate the situation in the latest
: release ..)

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




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

* Re: Initialized global data
  1998-05-05  0:00 Initialized global data Kevin Wells
                   ` (3 preceding siblings ...)
  1998-05-06  0:00 ` Tucker Taft
@ 1998-05-09  0:00 ` Niklas Holsti
  4 siblings, 0 replies; 13+ messages in thread
From: Niklas Holsti @ 1998-05-09  0:00 UTC (permalink / raw)



Kevin Wells wrote:
> 
> When specifying data in an Ada package that is pre-initialized such as
> ----------------------------------------
> package Generate_Matrix is
>   Scale_Factor : float := 10.903;
>   .
> end Generate_Matrix; -- spec
> ----------------------------------------
> 
> 1. Is it normal for the compiler to generate code that sets the value in
> memory
>     (that gets executed when the runtime system is initialized)?
> 2. Is there a way to get around this?


In the compiler we have used most (TLD Ada 83, cross from Solaris to
1750A)
there are a couple of compiler switches (-xtra -static_init) that can
be used to eliminate the initialization code, in favour of data placed
in the memory image for direct loading. Works only for _scalar_
variables
though. The same is automatic for all _constants_, as far as I know.

I know that you are using a different compiler, but perhaps a recheck
of the available compiler options would turn up something -- probably
you have already checked.

Niklas Holsti
Space Systems Finland




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

* Re: Initialized global data
  1998-05-08  0:00     ` Tucker Taft
@ 1998-05-09  0:00       ` Simon Wright
  1998-05-10  0:00         ` Robert Dewar
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Wright @ 1998-05-09  0:00 UTC (permalink / raw)



stt@houdini.camb.inmet.com (Tucker Taft) writes:

> Simon Wright (simon@pogner.demon.co.uk) wrote:
> 
> : nobody@REPLAY.COM (Anonymous) writes:
> : [...]
> : > Or you can use an uninitialized "variable" (that doesn't) at a specified
> : > address:
> : > 
> : > X : T;
> : > for X'Address use A; -- Ada 83: "for X use at A;"
> 
> : I'm not sure of chapter-and-verse, but I believe that a compiler is
> : allowed to initialize X here under some circumstances; which wouldn't
> : be what you wanted!
> 
> A "pragma Import(Ada, X);" would prevent initialization.

I saw (searching the AARM for 'implicit initialization' and 'default
initialization') that a pragma Import would do the trick but I must
say it never occured to me to do this!

So, to get it straight, if I have the code below

with System;
with System.Storage_Elements;
package Foo is
  Vme_Address : constant System.Address
     := System.Storage_Elements.To_Address (16#1_000_000#);
  Vme_Items : array (0 .. 16#1_000#) of Integer;
  for Vme_Items'Address use Vme_Address;
  pragma Import (Ada, Vme_Items);
end Foo;

and I want to be quite sure that Vme_Items isn't initialized, the Ada
idiom is to include the pragma Import line?




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

* Re: Initialized global data
  1998-05-09  0:00       ` Simon Wright
@ 1998-05-10  0:00         ` Robert Dewar
  1998-05-11  0:00           ` Simon Wright
  0 siblings, 1 reply; 13+ messages in thread
From: Robert Dewar @ 1998-05-10  0:00 UTC (permalink / raw)



Simon says

<<I saw (searching the AARM for 'implicit initialization' and 'default
initialization') that a pragma Import would do the trick but I must
say it never occured to me to do this!
>>

No need to rummage around in the AARM here, the rule is quite clear
and explicit in the RM (B.1(24))

24   The declaration of an imported object shall not include an explicit
initialization expression.  Default initializations are not performed.






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

* Re: Initialized global data
  1998-05-10  0:00         ` Robert Dewar
@ 1998-05-11  0:00           ` Simon Wright
  1998-05-11  0:00             ` Matthew Heaney
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Wright @ 1998-05-11  0:00 UTC (permalink / raw)



dewar@merv.cs.nyu.edu (Robert Dewar) writes:

> Simon says
> 
> <<I saw (searching the AARM for 'implicit initialization' and 'default
> initialization') that a pragma Import would do the trick but I must
> say it never occured to me to do this!
> >>
> 
> No need to rummage around in the AARM here, the rule is quite clear
> and explicit in the RM (B.1(24))
> 
> 24   The declaration of an imported object shall not include an explicit
> initialization expression.  Default initializations are not performed.

My AARM is more searchable than my RM.

Yes, I saw that clause, indeed that was the point of "a pragma Import
would do the trick", what I meant was that

  I : Integer;
  pragma Import (Ada, I);  -- prevent default initialization
  for I'Address use ...

is (IMHO) a non-obvious construction! (but thanks very much to all
who've helped).

There are just so many idioms in Ada, do we have a budding Coplien?




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

* Re: Initialized global data
  1998-05-11  0:00           ` Simon Wright
@ 1998-05-11  0:00             ` Matthew Heaney
  0 siblings, 0 replies; 13+ messages in thread
From: Matthew Heaney @ 1998-05-11  0:00 UTC (permalink / raw)



In article <x7vaf8o4mkp.fsf@pogner.demon.co.uk>, Simon Wright
<simon@pogner.demon.co.uk> wrote:

(start of quote)
There are just so many idioms in Ada, do we have a budding Coplien?
(end of quote)

This is on my list of Things To Do.  I've been compiling a list of such
idioms, and would like to document them in book form.  Maybe this summer
(which is not that far away actually...).




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

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

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-05  0:00 Initialized global data Kevin Wells
1998-05-05  0:00 ` A little more data Kevin Wells
1998-05-06  0:00   ` Stephen Leake
1998-05-06  0:00 ` Initialized global data Anonymous
1998-05-08  0:00   ` Simon Wright
1998-05-08  0:00     ` Tucker Taft
1998-05-09  0:00       ` Simon Wright
1998-05-10  0:00         ` Robert Dewar
1998-05-11  0:00           ` Simon Wright
1998-05-11  0:00             ` Matthew Heaney
1998-05-06  0:00 ` John English
1998-05-06  0:00 ` Tucker Taft
1998-05-09  0:00 ` Niklas Holsti

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