comp.lang.ada
 help / color / mirror / Atom feed
* Package with initialization only
@ 1999-07-21  0:00 Gautier
  1999-07-21  0:00 ` Robert A Duff
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Gautier @ 1999-07-21  0:00 UTC (permalink / raw)


Hi everybody!

A small "aesthetic" problem: I have a package with initialization only;
thus I must add a dummy procedure to resolve the with/without body
ambiguity Ada95 doesn't accept. There is surely a more elegant formulation,
surely with OO, since the initialization procedure affects the public
variable of the package. Its present state:

----****
with Engine_3D;

package Vehic001 is

  vehicle_001: Engine_3D.Object_3D( Max_points=> 100, Max_faces=> 86 );

private

  procedure dummy_proc;

end Vehic001;
----****

-- 
Gautier

--------
http://members.xoom.com/gdemont/




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

* Re: Package with initialization only
  1999-07-21  0:00 Package with initialization only Gautier
  1999-07-21  0:00 ` Robert A Duff
  1999-07-21  0:00 ` Ted Dennison
@ 1999-07-21  0:00 ` Martin C. Carlisle
  1999-07-21  0:00 ` Gautier de Montmollin
  1999-07-22  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 13+ messages in thread
From: Martin C. Carlisle @ 1999-07-21  0:00 UTC (permalink / raw)


In article <37961DD6.E56BD3E9@maths.unine.ch>,
Gautier  <gautier.demontmollin@maths.unine.ch> wrote:
>A small "aesthetic" problem: I have a package with initialization only;
>thus I must add a dummy procedure to resolve the with/without body
>ambiguity Ada95 doesn't accept. There is surely a more elegant formulation,
>surely with OO, since the initialization procedure affects the public
>variable of the package. Its present state:

You can also use "pragma Elaborate_Body;", as in:

package test_elab is
   pragma Elaborate_Body;
   
   x : integer;
end test_elab;

--Martin

-- 
Martin C. Carlisle, Asst Prof of Computer Science, US Air Force Academy
carlislem@acm.org, http://www.usafa.af.mil/dfcs/bios/carlisle.html
DISCLAIMER:  This content in no way reflects the opinions, standards or 
policy of the US Air Force Academy or the United States Government.




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

* Re: Package with initialization only
  1999-07-21  0:00 Package with initialization only Gautier
  1999-07-21  0:00 ` Robert A Duff
@ 1999-07-21  0:00 ` Ted Dennison
  1999-07-21  0:00   ` Samuel T. Harris
  1999-07-21  0:00 ` Martin C. Carlisle
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Ted Dennison @ 1999-07-21  0:00 UTC (permalink / raw)


In article <37961DD6.E56BD3E9@maths.unine.ch>,
  Gautier <gautier.demontmollin@maths.unine.ch> wrote:
> A small "aesthetic" problem: I have a package with initialization
only;
> thus I must add a dummy procedure to resolve the with/without body
> ambiguity Ada95 doesn't accept. There is surely a more elegant
formulation,

Well, perhaps it would be more pleasing if you renamed your dummy
routine "Initialize" and moved all the initialization code into it. If
you put it into the public part that would even allow others to
reinitialize the variable.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Package with initialization only
  1999-07-21  0:00 Package with initialization only Gautier
@ 1999-07-21  0:00 ` Robert A Duff
  1999-07-21  0:00 ` Ted Dennison
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 13+ messages in thread
From: Robert A Duff @ 1999-07-21  0:00 UTC (permalink / raw)


Gautier <gautier.demontmollin@maths.unine.ch> writes:

> A small "aesthetic" problem: I have a package with initialization only;
> thus I must add a dummy procedure to resolve the with/without body
> ambiguity Ada95 doesn't accept.

If you put "pragma Elaborate_Body;" at the beginning of the package
spec, then you're allowed to have a body.  In fact, *required* to have a
body.

In Ada 83, some people preferred a dummy incomplete type, instead of a
dummy procedure.

- Bob
-- 
Change robert to bob to get my real email address.  Sorry.




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

* Re: Package with initialization only
  1999-07-21  0:00 Package with initialization only Gautier
                   ` (2 preceding siblings ...)
  1999-07-21  0:00 ` Martin C. Carlisle
@ 1999-07-21  0:00 ` Gautier de Montmollin
  1999-07-22  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 13+ messages in thread
From: Gautier de Montmollin @ 1999-07-21  0:00 UTC (permalink / raw)


Thank you for the "pragma Elaborate_Body;" hint!

Gautier




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

* Re: Package with initialization only
  1999-07-21  0:00 ` Ted Dennison
@ 1999-07-21  0:00   ` Samuel T. Harris
  1999-07-21  0:00     ` David C. Hoos, Sr.
  1999-07-22  0:00     ` David Kristola
  0 siblings, 2 replies; 13+ messages in thread
From: Samuel T. Harris @ 1999-07-21  0:00 UTC (permalink / raw)


Ted Dennison wrote:
> 
> In article <37961DD6.E56BD3E9@maths.unine.ch>,
>   Gautier <gautier.demontmollin@maths.unine.ch> wrote:
> > A small "aesthetic" problem: I have a package with initialization
> only;
> > thus I must add a dummy procedure to resolve the with/without body
> > ambiguity Ada95 doesn't accept. There is surely a more elegant
> formulation,
> 
> Well, perhaps it would be more pleasing if you renamed your dummy
> routine "Initialize" and moved all the initialization code into it. If
> you put it into the public part that would even allow others to
> reinitialize the variable.
> 

While I don't disagree with Ted's suggestion,
I do want to point out that many times the
"intialization" must be done only once, preferably
during elaboration. In such cases, I call the
procedure "elaborate" and call it in the package body.
I feel the name elaborate conveys the restriction
of single initialization

In my experience, a common need for an elaborate
procedure is a variable which is an array of access
to strings. The strings may change over time and I
don't want the entire package body recompiling because
of such changes. By using an "initialize" or "elaborate"
procedure, I can make it a separate unit thus
isolating the compilation impact. 

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"




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

* Re: Package with initialization only
  1999-07-21  0:00   ` Samuel T. Harris
@ 1999-07-21  0:00     ` David C. Hoos, Sr.
  1999-07-22  0:00     ` David Kristola
  1 sibling, 0 replies; 13+ messages in thread
From: David C. Hoos, Sr. @ 1999-07-21  0:00 UTC (permalink / raw)



Samuel T. Harris <sam_harris@hso.link.com> wrote in message
news:37964947.5C95E5D1@hso.link.com...
> Ted Dennison wrote:
> >
Use Pragma Elaborate_Body in the spec, and it will
allow/require a body!

RM 10.2.1 (25) If a pragma Elaborate_Body applies to a declaration,
then the declaration requires a completion (a body).





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

* Re: Package with initialization only
  1999-07-21  0:00   ` Samuel T. Harris
  1999-07-21  0:00     ` David C. Hoos, Sr.
@ 1999-07-22  0:00     ` David Kristola
  1999-07-22  0:00       ` Marin David Condic
                         ` (2 more replies)
  1 sibling, 3 replies; 13+ messages in thread
From: David Kristola @ 1999-07-22  0:00 UTC (permalink / raw)


"Samuel T. Harris" <sam_harris@hso.link.com> () writes:
>Ted Dennison wrote:
>> 
>> In article <37961DD6.E56BD3E9@maths.unine.ch>,
>>   Gautier <gautier.demontmollin@maths.unine.ch> wrote:
>> > A small "aesthetic" problem: I have a package with initialization
>> only;
>> > thus I must add a dummy procedure to resolve the with/without body
>> > ambiguity Ada95 doesn't accept. There is surely a more elegant
>> formulation,
>> 
>> Well, perhaps it would be more pleasing if you renamed your dummy
>> routine "Initialize" and moved all the initialization code into it. If
>> you put it into the public part that would even allow others to
>> reinitialize the variable.
>> 
>
>While I don't disagree with Ted's suggestion,
>I do want to point out that many times the
>"intialization" must be done only once, preferably
>during elaboration. In such cases, I call the
>procedure "elaborate" and call it in the package body.
>I feel the name elaborate conveys the restriction
>of single initialization

Maybe it is my real-time embedded systems background,
but i much prefer explicit initialization over
elaboration.  The example that immediately comes to
mind is a case where the elaboration code wrote over
a memory mapped bus and sometimes caused contention
interrupts.  There was a handler to deal with the
situation, but it was not installed yet.
Installation of interrupt handlers was the first
thing the main program did after elaboration.


--djk, keeper of arcane lore & trivial fluff
Home: David95037 at aol dot com
Spam: goto.hades@welovespam.com





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

* Re: Package with initialization only
  1999-07-22  0:00     ` David Kristola
  1999-07-22  0:00       ` Marin David Condic
@ 1999-07-22  0:00       ` Ted Dennison
  1999-07-22  0:00       ` Samuel T. Harris
  2 siblings, 0 replies; 13+ messages in thread
From: Ted Dennison @ 1999-07-22  0:00 UTC (permalink / raw)


In article <7n65nl$1ru2@svlss.lmms.lmco.com>,
  dkristol@see-my.sig wrote:
> "Samuel T. Harris" <sam_harris@hso.link.com> () writes:
> Maybe it is my real-time embedded systems background,
> but i much prefer explicit initialization over
> elaboration.  The example that immediately comes to
> mind is a case where the elaboration code wrote over
> a memory mapped bus and sometimes caused contention

Agree completely. Also doing large amounts of work during elaboration
tends to lead to elaboration order problems, often manifested as hard to
track down Program_Error's that may go away or reappear or move around
every time a new unit is added. There's also the issue that many
debuggers make it difficult to stop or step in elaboration code.

There's also the confusing situation where the package needs to be
with'ed in by the main unit so that its elaboration code can run, even
though no unit in the entire program actually *uses* an entity from the
pacakge's spec. %-(  Its very tempting to remove the "with"s, as leaving
in obsolete "with"s is a common programmer error. Putting the
elaboration code into an "Initialize" routine that gets called by the
main unit makes it much more explicit what's going on (and very often
gives the main unit some small semblance of a job to do).

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Package with initialization only
  1999-07-22  0:00     ` David Kristola
@ 1999-07-22  0:00       ` Marin David Condic
  1999-07-22  0:00         ` laoxhai
  1999-07-22  0:00       ` Ted Dennison
  1999-07-22  0:00       ` Samuel T. Harris
  2 siblings, 1 reply; 13+ messages in thread
From: Marin David Condic @ 1999-07-22  0:00 UTC (permalink / raw)


David Kristola wrote:
> 
> Maybe it is my real-time embedded systems background,
> but i much prefer explicit initialization over
> elaboration.  The example that immediately comes to
> mind is a case where the elaboration code wrote over
> a memory mapped bus and sometimes caused contention
> interrupts.  There was a handler to deal with the
> situation, but it was not installed yet.
> Installation of interrupt handlers was the first
> thing the main program did after elaboration.
> 
In the embedded world, elaboration can sometimes cause serious troubles.
For example, in an application where the program begins execution in
EEPROM and has to copy itself to RAM before it can start writing to
memory, elaboration can be a problem. I've even had trouble with
compilers that wanted to dynamically initialize static constants at
elaboration (I guess to simplify the case where a constant might have a
dynamically determined value) which is really a bad idea if you want to
locate the constants in EEPROM. 

Which is, of course, not to say that elaboration in embedded computers
is *always* a bad thing. Its only once in a while that it gets
difficult. ;-)

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
***To reply, remove "bogon" from the domain name.***

Visit my web page at: http://www.mcondic.com/




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

* Re: Package with initialization only
  1999-07-22  0:00     ` David Kristola
  1999-07-22  0:00       ` Marin David Condic
  1999-07-22  0:00       ` Ted Dennison
@ 1999-07-22  0:00       ` Samuel T. Harris
  2 siblings, 0 replies; 13+ messages in thread
From: Samuel T. Harris @ 1999-07-22  0:00 UTC (permalink / raw)


David Kristola wrote:
> 
> "Samuel T. Harris" <sam_harris@hso.link.com> () writes:
> >Ted Dennison wrote:
> >>
> >> In article <37961DD6.E56BD3E9@maths.unine.ch>,
> >>   Gautier <gautier.demontmollin@maths.unine.ch> wrote:
> >> > A small "aesthetic" problem: I have a package with initialization
> >> only;
> >> > thus I must add a dummy procedure to resolve the with/without body
> >> > ambiguity Ada95 doesn't accept. There is surely a more elegant
> >> formulation,
> >>
> >> Well, perhaps it would be more pleasing if you renamed your dummy
> >> routine "Initialize" and moved all the initialization code into it. If
> >> you put it into the public part that would even allow others to
> >> reinitialize the variable.
> >>
> >
> >While I don't disagree with Ted's suggestion,
> >I do want to point out that many times the
> >"intialization" must be done only once, preferably
> >during elaboration. In such cases, I call the
> >procedure "elaborate" and call it in the package body.
> >I feel the name elaborate conveys the restriction
> >of single initialization
> 
> Maybe it is my real-time embedded systems background,
> but i much prefer explicit initialization over
> elaboration.  The example that immediately comes to
> mind is a case where the elaboration code wrote over
> a memory mapped bus and sometimes caused contention
> interrupts.  There was a handler to deal with the
> situation, but it was not installed yet.
> Installation of interrupt handlers was the first
> thing the main program did after elaboration.
> 

This post and the two that follow reinforce my point.
To me, initialization may or may not occur more than
one, but elaboration can ONLY occur once. Whether or
not the elaborate procedure is called in the package
body, or deferred to the main program is an architectural
consideration. In a simulator being produced here,
what would normally be elaborate code cannot be done
until the controlling tasks are running to schedule
the work. So these "elaboration" routine are distinct
from other "initialize" routines and are part of
the architectural framework.

I'm not sure if Dave meant to disagree or support me.
My elaborate routine is explicit initialization.
Architectural considerations determine where it is
called. I use the procedure name elaborate to
distinguish once-only intialization which must
occur early on in the running program before
stuff in its package is actually used with _normal_
initialization which may or may occur many times
but needs be done before accessing a particular
feature or variable.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"




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

* Re: Package with initialization only
  1999-07-22  0:00       ` Marin David Condic
@ 1999-07-22  0:00         ` laoxhai
  0 siblings, 0 replies; 13+ messages in thread
From: laoxhai @ 1999-07-22  0:00 UTC (permalink / raw)


In article <379728EA.5593E00E@pwfl.com>,
	Marin David Condic <condicma@bogon.pwfl.com> wrote:

>In the embedded world, elaboration can sometimes cause serious troubles.
>For example, in an application where the program begins execution in
>EEPROM and has to copy itself to RAM before it can start writing to
>memory, elaboration can be a problem. I've even had trouble with
>compilers that wanted to dynamically initialize static constants at
>elaboration (I guess to simplify the case where a constant might have a
>dynamically determined value) which is really a bad idea if you want to
>locate the constants in EEPROM. 

Geoff Mendal suggested an interesting approach to this problem a 
long time ago.  Target elaboration by making problematic packages
generic.  Then, no elaboration will occur until instantiation.  For
example,

          generic
          package Bit_Twirler is
            type Bits is ...
            procedure Twirl(The_Bits : in out Bits);
            -- Lots of other good stuff
          end Bit_Twirler;

          with Bit_Twirler;
          with A, B, C, D, E, G, H;  
          procedure Data_Sloshing is
             -- declare lots of variables, etc.
          begin
              declare
                package BT is new Bit_Twirler;
                -- BT only elaborates here
                Local_Bits :  BT.Bits;
              begin
                 BT.Twirl(The_Bits => Local_Bits);
              end;
          end Data_Sloshing;
            
Using this technique, there is absolutely no question of where the
with'd unit will first elaborate, no question of its scope, and no
issues related to where it can be visible.  This is a little bit of
overkill, but has worked out well in a few Ada 83 projects where a
large number of packages needed well defined elaboration.

Richard Riehle
richard@adaworks.com
http://www.adaworks.com




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

* Re: Package with initialization only
  1999-07-21  0:00 Package with initialization only Gautier
                   ` (3 preceding siblings ...)
  1999-07-21  0:00 ` Gautier de Montmollin
@ 1999-07-22  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 13+ messages in thread
From: Robert I. Eachus @ 1999-07-22  0:00 UTC (permalink / raw)




Gautier wrote:
 
> A small "aesthetic" problem: I have a package with initialization only;
> thus I must add a dummy procedure to resolve the with/without body
> ambiguity Ada95 doesn't accept. There is surely a more elegant formulation,
> surely with OO, since the initialization procedure affects the public
> variable of the package. Its present state:

  This was considered when the change in the rule for package bodies was
made,  the solution was to add a legality rule--RM 10.2.1(25):  "If a
pragma Elaborate_Body applies to a declaration, then the declaration
requies a completion (a body)."
 
-- 

                                        Robert I. Eachus

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




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

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

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-21  0:00 Package with initialization only Gautier
1999-07-21  0:00 ` Robert A Duff
1999-07-21  0:00 ` Ted Dennison
1999-07-21  0:00   ` Samuel T. Harris
1999-07-21  0:00     ` David C. Hoos, Sr.
1999-07-22  0:00     ` David Kristola
1999-07-22  0:00       ` Marin David Condic
1999-07-22  0:00         ` laoxhai
1999-07-22  0:00       ` Ted Dennison
1999-07-22  0:00       ` Samuel T. Harris
1999-07-21  0:00 ` Martin C. Carlisle
1999-07-21  0:00 ` Gautier de Montmollin
1999-07-22  0:00 ` Robert I. Eachus

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