comp.lang.ada
 help / color / mirror / Atom feed
* Generics & Elaboration Order
@ 2000-05-08  0:00 Andrew Logue
  2000-05-09  0:00 ` Robert Dewar
  2000-05-09  0:00 ` Robert A Duff
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Logue @ 2000-05-08  0:00 UTC (permalink / raw)


Hello,

I need help to instantiate a generic package with an actual parameter whose 
value must be determined at run-time.

Please take a peek at the following pseudo-code:


package body main is

  Actual_Parameter : Boolean := False;
  package New_Pack is new Generic_Package( Parameter => Actual_Parameter );

  begin  -- package elaboration code

    if some_package.embedded_computer_type = some_package.type_A then

      Actual_Parameter := True;
 
    else

      Actual_Parameter := False;

    end if;


end main;

Given the above code, and the embedded computer type is type_A, will 
New_Pack be instantiated with an Actual_Parameter value of True or False?

i.e. does the code in package body execute before the generic is 
instantiated?


Thank you for your feedback,

Andrew Logue,
Computing Devices Canada.




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

* Re: Generics & Elaboration Order
  2000-05-08  0:00 Generics & Elaboration Order Andrew Logue
@ 2000-05-09  0:00 ` Robert Dewar
  2000-05-18  0:00   ` ANTHONY GAIR
  2000-05-09  0:00 ` Robert A Duff
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Dewar @ 2000-05-09  0:00 UTC (permalink / raw)


In article <8F2E930FAandrewloguecdcgycom@142.77.1.194>,
  nospam.andrew.logue@cdcgy.com (Andrew Logue) wrote:
> i.e. does the code in package body execute before the generic
> is instantiated?

No, certainly not

Generally the linear elaboration semantics of Ada mean that
an expression is evaluated when you come to it. There are
very few exceptions to this rule (default expressions in
specs are one case, generic templates are the other).


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Generics & Elaboration Order
  2000-05-08  0:00 Generics & Elaboration Order Andrew Logue
  2000-05-09  0:00 ` Robert Dewar
@ 2000-05-09  0:00 ` Robert A Duff
  1 sibling, 0 replies; 7+ messages in thread
From: Robert A Duff @ 2000-05-09  0:00 UTC (permalink / raw)


nospam.andrew.logue@cdcgy.com (Andrew Logue) writes:

> package body main is
> 
>   Actual_Parameter : Boolean := False;
>   package New_Pack is new Generic_Package( Parameter => Actual_Parameter );
> 
>   begin  -- package elaboration code
> 
>     if some_package.embedded_computer_type = some_package.type_A then
> 
>       Actual_Parameter := True;
>  
>     else
> 
>       Actual_Parameter := False;
> 
>     end if;
> 
> 
> end main;
> 
> Given the above code, and the embedded computer type is type_A, will 
> New_Pack be instantiated with an Actual_Parameter value of True or False?

I presume Parameter is mode 'in'.  In that case, False is passed.

If Parameter is mode 'in out', then it's like a renaming,
but I don't think that's what you're talking about.

> i.e. does the code in package body execute before the generic is 
> instantiated?

No.

- Bob




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

* Re: Generics & Elaboration Order
  2000-05-09  0:00 ` Robert Dewar
@ 2000-05-18  0:00   ` ANTHONY GAIR
  2000-05-18  0:00     ` Robert A Duff
  0 siblings, 1 reply; 7+ messages in thread
From: ANTHONY GAIR @ 2000-05-18  0:00 UTC (permalink / raw)


you could try (before package is referred to .)

pragma elaborate(name_of_package);

 this will force the compiler to pull this package in, before compilation of
the rest of the code.
**********************************************

Are ADA and linux a good combination ?:-
visit www.remotely.useful.com - under construction




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

* Re: Generics & Elaboration Order
  2000-05-18  0:00   ` ANTHONY GAIR
@ 2000-05-18  0:00     ` Robert A Duff
  2000-05-19  0:00       ` ANTHONY GAIR
  0 siblings, 1 reply; 7+ messages in thread
From: Robert A Duff @ 2000-05-18  0:00 UTC (permalink / raw)


anthonygair@aol.comremoveme (ANTHONY GAIR) writes:

> pragma elaborate(name_of_package);

You should almost always use pragma Elaborate_All instead of pragma
Elaborate.

- Bob




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

* Re: Generics & Elaboration Order
  2000-05-18  0:00     ` Robert A Duff
@ 2000-05-19  0:00       ` ANTHONY GAIR
  2000-05-21  0:00         ` Robert Dewar
  0 siblings, 1 reply; 7+ messages in thread
From: ANTHONY GAIR @ 2000-05-19  0:00 UTC (permalink / raw)



whats the difference Bob ?
**********************************************

Are ADA and linux a good combination ?:-
visit www.remotely.useful.com - under construction




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

* Re: Generics & Elaboration Order
  2000-05-19  0:00       ` ANTHONY GAIR
@ 2000-05-21  0:00         ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 2000-05-21  0:00 UTC (permalink / raw)


In article <20000518204425.29388.00000121@ng-cm1.aol.com>,

> whats the difference Bob ?

[between Elaborate and Elaborate_All]

This is a pretty standard issue, any decent Ada text book
should describe how Elaborate_All works. See also the
Ada Rationale for a discussoin of the need for this
new feature.

Don't assume that brief posts to CLA, even if people are
willing to repeat standard stuff, substitute for the careful
and complete discussions that can easily be located in
appropriate reference materials. The Rationale is a particularly
useful document.



Sent via Deja.com http://www.deja.com/
Before you buy.




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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-08  0:00 Generics & Elaboration Order Andrew Logue
2000-05-09  0:00 ` Robert Dewar
2000-05-18  0:00   ` ANTHONY GAIR
2000-05-18  0:00     ` Robert A Duff
2000-05-19  0:00       ` ANTHONY GAIR
2000-05-21  0:00         ` Robert Dewar
2000-05-09  0:00 ` 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