comp.lang.ada
 help / color / mirror / Atom feed
* package body functionality
@ 2001-05-26 14:28 Staffan Dittmer
  2001-05-26 17:09 ` Larry Kilgallen
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: Staffan Dittmer @ 2001-05-26 14:28 UTC (permalink / raw)


the question might be a bit obscure but 
considering the two package bodies below

package body A is
 variable: some_type:=call_some_function_outside_A;
end A;

package body B is
 variable: some_type;
begin
 variable:=call_some_function_outside_B;
end B;

I know that in B the variable will be assigned
every time a program using the package is run,
but is this also true for A, or will the variable in 
this case only be assigned at compile time ?

saturdays usually makes me confused...

/ Staffan Dittmer



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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
@ 2001-05-26 17:09 ` Larry Kilgallen
  2001-05-26 17:22 ` Jeffrey Carter
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Larry Kilgallen @ 2001-05-26 17:09 UTC (permalink / raw)


In article <9eoeiv$h8$1@eol.dd.chalmers.se>, f97stdi@dd.chalmers.se (Staffan Dittmer) writes:
> the question might be a bit obscure but 
> considering the two package bodies below
> 
> package body A is
>  variable: some_type:=call_some_function_outside_A;
> end A;
> 
> package body B is
>  variable: some_type;
> begin
>  variable:=call_some_function_outside_B;
> end B;
> 
> I know that in B the variable will be assigned
> every time a program using the package is run,
> but is this also true for A, or will the variable in 
> this case only be assigned at compile time ?

call_some_function_outside_A has a body unknown to A,
and the results of that call could be time-variant,
such as computed differently on weekends.  A has no
way of knowing this, so the results cannot be computed
"at compile time".



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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
  2001-05-26 17:09 ` Larry Kilgallen
@ 2001-05-26 17:22 ` Jeffrey Carter
  2001-05-26 18:31   ` DuckE
  2001-05-26 19:16 ` Aron Felix Gurski
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 16+ messages in thread
From: Jeffrey Carter @ 2001-05-26 17:22 UTC (permalink / raw)


Staffan Dittmer wrote:
> 
> package body A is
>  variable: some_type:=call_some_function_outside_A;
> end A;
> 
> package body B is
>  variable: some_type;
> begin
>  variable:=call_some_function_outside_B;
> end B;
> 
> I know that in B the variable will be assigned
> every time a program using the package is run,
> but is this also true for A, or will the variable in
> this case only be assigned at compile time ?

Non-static initialization expressions, such as function calls, are
evaluated during elaboration, which happens at run time. Both variables
will be initialized during elaboration at run time.

-- 
Jeff Carter
"You tiny-brained wipers of other people's bottoms!"
Monty Python & the Holy Grail



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

* Re: package body functionality
  2001-05-26 17:22 ` Jeffrey Carter
@ 2001-05-26 18:31   ` DuckE
  0 siblings, 0 replies; 16+ messages in thread
From: DuckE @ 2001-05-26 18:31 UTC (permalink / raw)



"Jeffrey Carter" <jrcarter@acm.org> wrote in message
news:3B0FE64F.7D574D2E@acm.org...
> Staffan Dittmer wrote:
> >
> > package body A is
> >  variable: some_type:=call_some_function_outside_A;
> > end A;
> >
> > package body B is
> >  variable: some_type;
> > begin
> >  variable:=call_some_function_outside_B;
> > end B;
> >
> > I know that in B the variable will be assigned
> > every time a program using the package is run,
> > but is this also true for A, or will the variable in
> > this case only be assigned at compile time ?
>
> Non-static initialization expressions, such as function calls, are
> evaluated during elaboration, which happens at run time. Both variables
> will be initialized during elaboration at run time.

Unless the compiler has a form of global optimization that determines
the result of performing the operation at compile time is the same as
evaluating
both at elaboration time (a nice optimization).

SteveD

>
> --
> Jeff Carter
> "You tiny-brained wipers of other people's bottoms!"
> Monty Python & the Holy Grail





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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
  2001-05-26 17:09 ` Larry Kilgallen
  2001-05-26 17:22 ` Jeffrey Carter
@ 2001-05-26 19:16 ` Aron Felix Gurski
  2001-05-27 13:50 ` Ken Garlington
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 16+ messages in thread
From: Aron Felix Gurski @ 2001-05-26 19:16 UTC (permalink / raw)


Staffan Dittmer wrote:
> 
> the question might be a bit obscure but
> considering the two package bodies below
> 
> package body A is
>  variable: some_type:=call_some_function_outside_A;
> end A;
> 
> package body B is
>  variable: some_type;
> begin
>  variable:=call_some_function_outside_B;
> end B;
> 
> I know that in B the variable will be assigned
> every time a program using the package is run,
> but is this also true for A, or will the variable in
> this case only be assigned at compile time ?
> 
> saturdays usually makes me confused...

The function of the compiler is to convert (in this case) package body A into
object code, not to execute the code in some other package (which, conceivably,
might not even be compiled yet).

-- 
        -- Aron

NB: To reply by e-mail, remove "spam-block." from my address.
- - - - - - - - - - -
"Nobody suffers the pain of birth or the anguish of loving a child in order for
presidents to make wars, for governments to feed on the substance of their
people, for insurance companies to cheat the young and rob the old."

        -- Lewis Lapham



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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
                   ` (2 preceding siblings ...)
  2001-05-26 19:16 ` Aron Felix Gurski
@ 2001-05-27 13:50 ` Ken Garlington
  2001-05-29  9:15   ` Philip Anderson
  2001-05-29 13:26 ` Ted Dennison
  2001-05-29 19:11 ` Stephen Leake
  5 siblings, 1 reply; 16+ messages in thread
From: Ken Garlington @ 2001-05-27 13:50 UTC (permalink / raw)


If you're asking "are these different," the only difference I can think of
is that a given compiler *might* optimize them differently, up to and
including eliminating the variable altogether!

"Staffan Dittmer" <f97stdi@dd.chalmers.se> wrote in message
news:9eoeiv$h8$1@eol.dd.chalmers.se...
: the question might be a bit obscure but
: considering the two package bodies below
:
: package body A is
:  variable: some_type:=call_some_function_outside_A;
: end A;
:
: package body B is
:  variable: some_type;
: begin
:  variable:=call_some_function_outside_B;
: end B;
:
: I know that in B the variable will be assigned
: every time a program using the package is run,
: but is this also true for A, or will the variable in
: this case only be assigned at compile time ?
:
: saturdays usually makes me confused...
:
: / Staffan Dittmer





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

* Re: package body functionality
  2001-05-27 13:50 ` Ken Garlington
@ 2001-05-29  9:15   ` Philip Anderson
  0 siblings, 0 replies; 16+ messages in thread
From: Philip Anderson @ 2001-05-29  9:15 UTC (permalink / raw)


Ken Garlington wrote:
> 
> If you're asking "are these different," the only difference I can think of
> is that a given compiler *might* optimize them differently, up to and
> including eliminating the variable altogether!


There could be other differences because of the order of actions,

e.g.

package body A is
  variable: some_type:=call_some_function_outside_A;
  V2 : some_type := variable;
end A;
&
package body B is
  variable: some_type;
  V2 : some_type := variable;  -- default/uninitialised value of
variable
begin
  variable:=call_some_function_outside_B;
end B;


The second option also allows you to include an exception handler to
catch any exception raised by function outside B

-- 
hwyl/cheers,
Philip Anderson
Alenia Marconi Systems
Cwmbr�n, Cymru/Wales



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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
                   ` (3 preceding siblings ...)
  2001-05-27 13:50 ` Ken Garlington
@ 2001-05-29 13:26 ` Ted Dennison
  2001-05-29 19:11 ` Stephen Leake
  5 siblings, 0 replies; 16+ messages in thread
From: Ted Dennison @ 2001-05-29 13:26 UTC (permalink / raw)


In article <9eoeiv$h8$1@eol.dd.chalmers.se>, Staffan Dittmer says...
>
>package body A is
> variable: some_type:=call_some_function_outside_A;
>end A;
..
>but is this also true for A, or will the variable in 
>this case only be assigned at compile time ?

Oddly enough, we had a very long discussion here a few months back about what it
would take for a compiler to be able to call a user-specified function at
compile time. If you're interested in that topic, you may want to try to look it
up at http://groups.google.com . I doubt we will recover all the better points
here again.


---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: package body functionality
  2001-05-26 14:28 package body functionality Staffan Dittmer
                   ` (4 preceding siblings ...)
  2001-05-29 13:26 ` Ted Dennison
@ 2001-05-29 19:11 ` Stephen Leake
  2001-05-29 20:34   ` Ted Dennison
  2001-05-31  1:37   ` Robert A Duff
  5 siblings, 2 replies; 16+ messages in thread
From: Stephen Leake @ 2001-05-29 19:11 UTC (permalink / raw)


f97stdi@dd.chalmers.se (Staffan Dittmer) writes:

> the question might be a bit obscure but 
> considering the two package bodies below
> 
> package body A is
>  variable: some_type:=call_some_function_outside_A;
> end A;
> 
> package body B is
>  variable: some_type;
> begin
>  variable:=call_some_function_outside_B;
> end B;
> 
> I know that in B the variable will be assigned
> every time a program using the package is run,

This is seriously wrong! B.variable is _not_ set many times. It
would be interesting to understand how you got that impression.

B.variable will be set _once_, at "elaboration" time. Elaboration
happens just before the main Ada program is run. All packages in the
program are elaborated, in an order determined by the compiler.

Note that if a function is called before its package is elaborated,
the exception Program_Error is raised; this is before your main
program gets to start.

To be safe, package A should have a 'pragma Elaborate' for the package
containing 'some_function_outside_A', and similarly for B.

> 
> but is this also true for A, or will the variable in this case only
> be assigned at compile time ?

As for B, A.variable is set at elaboration time.

-- 
-- Stephe



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

* Re: package body functionality
  2001-05-29 19:11 ` Stephen Leake
@ 2001-05-29 20:34   ` Ted Dennison
  2001-05-29 21:29     ` Marin David Condic
  2001-05-30 14:23     ` Stephen Leake
  2001-05-31  1:37   ` Robert A Duff
  1 sibling, 2 replies; 16+ messages in thread
From: Ted Dennison @ 2001-05-29 20:34 UTC (permalink / raw)


In article <u66ekm0m5.fsf@gsfc.nasa.gov>, Stephen Leake says...
>
>f97stdi@dd.chalmers.se (Staffan Dittmer) writes:
>
>> package body B is
>>  variable: some_type;
>> begin
>>  variable:=call_some_function_outside_B;
>> end B;
>> 
>> I know that in B the variable will be assigned
>> every time a program using the package is run,
>
>This is seriously wrong! B.variable is _not_ set many times. It
>would be interesting to understand how you got that impression.

He said every time the *program* is run, which is quite correct. I'll admit the
possiblity that he meant something else (although I'm having trouble mentally
concoting a reasonable alternative), but that's not what he wrote.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: package body functionality
  2001-05-29 20:34   ` Ted Dennison
@ 2001-05-29 21:29     ` Marin David Condic
  2001-05-30 13:46       ` Ted Dennison
  2001-05-30 14:23     ` Stephen Leake
  1 sibling, 1 reply; 16+ messages in thread
From: Marin David Condic @ 2001-05-29 21:29 UTC (permalink / raw)


Possible exception: If the package is a shared library or in a distributed
environment. I'm not sure what the language rules are, but I'd suspect that
a DLL would not re-elaborate every time another program started up and
called for its services. Maybe under some conditions (separate data spaces)
but not if it was some sort of shared resource. Or would it?

Interesting question - maybe I'll have to look up "Elaboration" tomorrow if
nobody posts an answer before I get back to work. :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Ted Dennison" <dennison@telepath.com> wrote in message
news:MJTQ6.4332$rn5.225402@www.newsranger.com...
> He said every time the *program* is run, which is quite correct. I'll
admit the
> possiblity that he meant something else (although I'm having trouble
mentally
> concoting a reasonable alternative), but that's not what he wrote.
>






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

* Re: package body functionality
  2001-05-29 21:29     ` Marin David Condic
@ 2001-05-30 13:46       ` Ted Dennison
  2001-05-30 14:25         ` Marin David Condic
  2001-05-31 19:08         ` Wes Groleau
  0 siblings, 2 replies; 16+ messages in thread
From: Ted Dennison @ 2001-05-30 13:46 UTC (permalink / raw)


In article <9f14b8$r4v$1@nh.pace.co.uk>, Marin David Condic says...
>
>Possible exception: If the package is a shared library or in a distributed
>environment. I'm not sure what the language rules are, but I'd suspect that
>a DLL would not re-elaborate every time another program started up and
>called for its services. Maybe under some conditions (separate data spaces)

My understanding is that DLL's keep a count of how many programs are using them,
and get automagicly unloaded when the count goes down to 0. You'd want it to
elaborate once for the first call that loads it in, then not again until the
next call after it unloads.

However, DLL's have their own special entry point as well. I suspect what Ada
DLL's have to do is implement that call (exported with the right linkage of
course) to call the standard Ada elaboration entry point. Perhaps someone who
has done this can comment.

Anyway, I wouldn't really call this an "exception". Its just that in this case
the "program" in question is the DLL itself, not its clients. It works if you
hold your head the right way. :-)

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: package body functionality
  2001-05-29 20:34   ` Ted Dennison
  2001-05-29 21:29     ` Marin David Condic
@ 2001-05-30 14:23     ` Stephen Leake
  1 sibling, 0 replies; 16+ messages in thread
From: Stephen Leake @ 2001-05-30 14:23 UTC (permalink / raw)


Ted Dennison<dennison@telepath.com> writes:

> In article <u66ekm0m5.fsf@gsfc.nasa.gov>, Stephen Leake says...
> >
> >f97stdi@dd.chalmers.se (Staffan Dittmer) writes:
> >
> >> package body B is
> >>  variable: some_type;
> >> begin
> >>  variable:=call_some_function_outside_B;
> >> end B;
> >> 
> >> I know that in B the variable will be assigned
> >> every time a program using the package is run,
> >
> >This is seriously wrong! B.variable is _not_ set many times. It
> >would be interesting to understand how you got that impression.
> 
> He said every time the *program* is run, which is quite correct. I'll admit the
> possiblity that he meant something else (although I'm having trouble mentally
> concoting a reasonable alternative), but that's not what he wrote.

Hmm, I guess I read "subprogram from the package", rather than
"program using the package". Sorry!

-- 
-- Stephe



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

* Re: package body functionality
  2001-05-30 13:46       ` Ted Dennison
@ 2001-05-30 14:25         ` Marin David Condic
  2001-05-31 19:08         ` Wes Groleau
  1 sibling, 0 replies; 16+ messages in thread
From: Marin David Condic @ 2001-05-30 14:25 UTC (permalink / raw)


Point taken. It is kind of a matter of how you look at it. I just brought it
up because its an example of the importance of looking over the
documentation for unusual cases. In 99.44% of the cases, you've got a
simple, self contained, program that elaborates when you run it. But there
may be cases where the elaboration has more subtle implications.

I'll try to hold my head right and look at it with the corner of my eyes
next time. It's the only way to see something that has an SEP field
surrounding it. :-)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Ted Dennison" <dennison@telepath.com> wrote in message
news:hR6R6.5195$rn5.257552@www.newsranger.com...
> Anyway, I wouldn't really call this an "exception". Its just that in this
case
> the "program" in question is the DLL itself, not its clients. It works if
you
> hold your head the right way. :-)
>






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

* Re: package body functionality
  2001-05-29 19:11 ` Stephen Leake
  2001-05-29 20:34   ` Ted Dennison
@ 2001-05-31  1:37   ` Robert A Duff
  1 sibling, 0 replies; 16+ messages in thread
From: Robert A Duff @ 2001-05-31  1:37 UTC (permalink / raw)


Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:

> To be safe, package A should have a 'pragma Elaborate' for the package
> containing 'some_function_outside_A', and similarly for B.

A pragma Elaborate_All is almost always better than pragma Elaborate,
because it is transitive.

- Bob



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

* Re: package body functionality
  2001-05-30 13:46       ` Ted Dennison
  2001-05-30 14:25         ` Marin David Condic
@ 2001-05-31 19:08         ` Wes Groleau
  1 sibling, 0 replies; 16+ messages in thread
From: Wes Groleau @ 2001-05-31 19:08 UTC (permalink / raw)



> >Possible exception: If the package is a shared library or in a distributed
> >environment. I'm not sure what the language rules are, but I'd suspect that
> >a DLL would not re-elaborate every time another program started up and
> >called for its services. Maybe under some conditions (separate data spaces)
> 
> My understanding is that DLL's keep a count of how many programs are using them,
> and get automagicly unloaded when the count goes down to 0. You'd want it to
> elaborate once for the first call that loads it in, then not again until the
> next call after it unloads.

There are many things a package in a DLL or shared lib might do during
elaboration that would require re-elaboration for each client.  Just for a
few:

  Create a log file.
  Initialize a random number generator.
  Read the process ID.
  Note the time we started running.

Doesn't seem practical for a compiler/linker to foresee ALL the possibilities
and optionally skip elaboration.

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



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

end of thread, other threads:[~2001-05-31 19:08 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-26 14:28 package body functionality Staffan Dittmer
2001-05-26 17:09 ` Larry Kilgallen
2001-05-26 17:22 ` Jeffrey Carter
2001-05-26 18:31   ` DuckE
2001-05-26 19:16 ` Aron Felix Gurski
2001-05-27 13:50 ` Ken Garlington
2001-05-29  9:15   ` Philip Anderson
2001-05-29 13:26 ` Ted Dennison
2001-05-29 19:11 ` Stephen Leake
2001-05-29 20:34   ` Ted Dennison
2001-05-29 21:29     ` Marin David Condic
2001-05-30 13:46       ` Ted Dennison
2001-05-30 14:25         ` Marin David Condic
2001-05-31 19:08         ` Wes Groleau
2001-05-30 14:23     ` Stephen Leake
2001-05-31  1:37   ` Robert A Duff

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