comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada 95 Compatibility
  1996-02-22  0:00 Ada 95 Compatibility John Herro
@ 1996-02-22  0:00 ` Mark A Biggar
  1996-02-23  0:00   ` PHILIP W. BRASHEAR
  1996-02-23  0:00 ` Ken Garlington
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Mark A Biggar @ 1996-02-22  0:00 UTC (permalink / raw)


In article <4gi8o8$an2@newsbf02.news.aol.com> johnherro@aol.com (John Herro) writes:
>     In Ada 95, a package spec. that doesn't *need* an corresponding body
>can't *have* one.  Here's a simplified program segment that I wrote in Ada
>83:

The proper solution to this problem is to include a 
pragma ELABORATE_BODY;
in the package spec, this forces the existence of a body for a package
where one would otherwise bre illegal.

--
Mark Biggar
mab@wdl.loral.com





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

* Ada 95 Compatibility
@ 1996-02-22  0:00 John Herro
  1996-02-22  0:00 ` Mark A Biggar
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: John Herro @ 1996-02-22  0:00 UTC (permalink / raw)


     In Ada 95, a package spec. that doesn't *need* an corresponding body
can't *have* one.  Here's a simplified program segment that I wrote in Ada
83:

package P is
   Buffer : array(1 .. 50) of Integer;
end P;

package body P is
begin
   -- code to initialize Buffer
end P;

     The buffer initialization is too complicated to do by initializing to
an aggregrate in the package spec., such as one would do if initializing
the buffer to all zeros.  Here's how I rewrote the code for Ada 95; I'm
wondering if I did it the best way:

package P is
   Buffer : array(1 .. 50) of Integer;
private
   procedure Init;
end P;

package body P is
   procedure Init is separate;
begin
   Init;
end P;

separate (P)
procedure Init is
begin
   -- code to initialize Buffer
end Init;

     There are other ways I could have done it.  I could have made
procedure Init public and required the main program to call it, but that
sounds worse to me.  I could have omitted the declaration of Init and
instead declared procedure Dummy that does nothing but give me the
opportunity to create a package body.  The package body would contain
"procedure Dummy is begin null; end Dummy;" which would never be called,
and the package body would initialize Buffer just as in the Ada 83
example.  This, too, seems worse than what I did.  However, what I did in
Ada 95 seems like a lot more lines of code that the Ada 83 version.  Do
you guys think I rewrote it the best way, or do you have other
suggestions?  Thanks.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

* Re: Ada 95 Compatibility
  1996-02-22  0:00 Ada 95 Compatibility John Herro
  1996-02-22  0:00 ` Mark A Biggar
  1996-02-23  0:00 ` Ken Garlington
@ 1996-02-23  0:00 ` Peter Amey
  1996-02-23  0:00 ` Keith Thompson
  3 siblings, 0 replies; 11+ messages in thread
From: Peter Amey @ 1996-02-23  0:00 UTC (permalink / raw)




On 22 Feb 1996, John Herro wrote:

>      In Ada 95, a package spec. that doesn't *need* an corresponding body
> can't *have* one.  Here's a simplified program segment that I wrote in Ada
> 83:
> 
[snip]
> Ada 95 seems like a lot more lines of code that the Ada 83 version.  Do
> you guys think I rewrote it the best way, or do you have other
> suggestions?  Thanks.
> 

Isn't the pragma ELABORATE_BODY intended for this situation?

Peter





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

* Re: Ada 95 Compatibility
  1996-02-22  0:00 Ada 95 Compatibility John Herro
                   ` (2 preceding siblings ...)
  1996-02-23  0:00 ` Peter Amey
@ 1996-02-23  0:00 ` Keith Thompson
  3 siblings, 0 replies; 11+ messages in thread
From: Keith Thompson @ 1996-02-23  0:00 UTC (permalink / raw)


In <4gi8o8$an2@newsbf02.news.aol.com> johnherro@aol.com (John Herro) writes:
>      In Ada 95, a package spec. that doesn't *need* an corresponding body
> can't *have* one.  Here's a simplified program segment that I wrote in Ada
> 83:
> 
> package P is
>    Buffer : array(1 .. 50) of Integer;
> end P;
> 
> package body P is
> begin
>    -- code to initialize Buffer
> end P;
> 
>      The buffer initialization is too complicated to do by initializing to
> an aggregrate in the package spec., such as one would do if initializing
> the buffer to all zeros.  Here's how I rewrote the code for Ada 95; I'm
> wondering if I did it the best way:
[chomp]

The simplest method is to add a pragma Elaborate_Body to the specification
of P, before the first declaration; this makes the body mandatory.

Other alternatives are to add an incomplete type to the private part,
which must be completed in the body, or to add a dummy procedure
declaration to the private part, which again must be completed in
the body.  (Note that there's no need to call the procedure; you can
still do the initialization in the statement part of the package body.)

-- 
Keith Thompson (The_Other_Keith) kst@thomsoft.com
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
"As God is my witness, I thought turkeys could fly." -- Arthur Carlson, WKRP




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

* Re: Ada 95 Compatibility
  1996-02-22  0:00 ` Mark A Biggar
@ 1996-02-23  0:00   ` PHILIP W. BRASHEAR
  0 siblings, 0 replies; 11+ messages in thread
From: PHILIP W. BRASHEAR @ 1996-02-23  0:00 UTC (permalink / raw)


mab@dst17.wdl.loral.com (Mark A Biggar) writes:

>In article <4gi8o8$an2@newsbf02.news.aol.com> johnherro@aol.com (John Herro) writes:
>>     In Ada 95, a package spec. that doesn't *need* an corresponding body
>>can't *have* one.  Here's a simplified program segment that I wrote in Ada
>>83:

>--
>Mark Biggar
>mab@wdl.loral.com

By the way, remember that this restriction is on LIBRARY packages -- not
nested packages.

Phil Brashear
CTA INCORPORATED




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

* Re: Ada 95 Compatibility
  1996-02-22  0:00 Ada 95 Compatibility John Herro
  1996-02-22  0:00 ` Mark A Biggar
@ 1996-02-23  0:00 ` Ken Garlington
  1996-02-24  0:00   ` John Herro
  1996-02-23  0:00 ` Peter Amey
  1996-02-23  0:00 ` Keith Thompson
  3 siblings, 1 reply; 11+ messages in thread
From: Ken Garlington @ 1996-02-23  0:00 UTC (permalink / raw)


John Herro wrote:
> 
>      In Ada 95, a package spec. that doesn't *need* an corresponding body
> can't *have* one.

See RM95-7.2:4.




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

* Re: Ada 95 Compatibility
  1996-02-23  0:00 ` Ken Garlington
@ 1996-02-24  0:00   ` John Herro
  1996-02-24  0:00     ` Robert Dewar
  0 siblings, 1 reply; 11+ messages in thread
From: John Herro @ 1996-02-24  0:00 UTC (permalink / raw)


I wrote:
>> In Ada 95, a package spec. that doesn't *need*
>> a corresponding body can't *have* one.

Ken Garlington <GarlingtonKE@lfwc.lockheed.com> replied:
> See RM95-7.2:4.

     Thanks to everyone who replied to my initial question.  Ken's RM
reference provides the best and simplest solution, to add pragma
Elaborate_Body as follows:

package P is
   pragma Elaborate_Body;
   Buffer : array(1 .. 50) of Integer;
end P;

package body P is
begin
   -- code to initialize Buffer
end P;

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor




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

* Re: Ada 95 Compatibility
  1996-02-24  0:00   ` John Herro
@ 1996-02-24  0:00     ` Robert Dewar
  1996-02-26  0:00       ` Ken Garlington
  0 siblings, 1 reply; 11+ messages in thread
From: Robert Dewar @ 1996-02-24  0:00 UTC (permalink / raw)


John Herro said

"     Thanks to everyone who replied to my initial question.  Ken's RM
reference provides the best and simplest solution, to add pragma
Elaborate_Body as follows:

package P is
   pragma Elaborate_Body;
   Buffer : array(1 .. 50) of Integer;
end P;

package body P is
begin
   -- code to initialize Buffer
end P;

Yes, that's certainly fine in Ada 95. If you want to stay Ada 83
compatible, then a method which works in both 83 and 95 is

package P is
   Buffer ...
private
   type Requires_Body;
end P;

then in the body you give a dummy completion for the incomplete type.





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

* Re: Ada 95 Compatibility
  1996-02-24  0:00     ` Robert Dewar
@ 1996-02-26  0:00       ` Ken Garlington
  1996-02-26  0:00         ` Robert Dewar
  1996-02-26  0:00         ` Robert Dewar
  0 siblings, 2 replies; 11+ messages in thread
From: Ken Garlington @ 1996-02-26  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> 
> Yes, that's certainly fine in Ada 95. If you want to stay Ada 83
> compatible...
> 
[other example snipped]

I figured that the pragma Elaborate_Body would work with Ada 83 as well, in
that the pragma would be ignored and the body allowed. If you're saying that
the second example is safer in Ada 83, since you can't "forget" to compile
the body, then I understand.




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

* Re: Ada 95 Compatibility
  1996-02-26  0:00       ` Ken Garlington
  1996-02-26  0:00         ` Robert Dewar
@ 1996-02-26  0:00         ` Robert Dewar
  1 sibling, 0 replies; 11+ messages in thread
From: Robert Dewar @ 1996-02-26  0:00 UTC (permalink / raw)


"I figured that the pragma Elaborate_Body would work with Ada 83 as well, in
that the pragma would be ignored and the body allowed. If you're saying that
the second example is safer in Ada 83, since you can't "forget" to compile
the body, then I understand."

Exactly, this is a real trap in Ada 83, and my approcah should be standard
practice in Ada 83 to avoid falling into that trap, and incidentally is
Ada 83 copatible.

Also the warning message for an ignored pragma may be, depending on
your environment, unacceptable (we compile GNAT with the -gnatwe switch
for example that makes warnings into fatal errors).





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

* Re: Ada 95 Compatibility
  1996-02-26  0:00       ` Ken Garlington
@ 1996-02-26  0:00         ` Robert Dewar
  1996-02-26  0:00         ` Robert Dewar
  1 sibling, 0 replies; 11+ messages in thread
From: Robert Dewar @ 1996-02-26  0:00 UTC (permalink / raw)


I said

Exactly, this is a real trap in Ada 83, and my approcah should be standard
practice in Ada 83 to avoid falling into that trap, and incidentally is
Ada 83 copatible.


Of course I meant Ada 95 compatible.





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

end of thread, other threads:[~1996-02-26  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-02-22  0:00 Ada 95 Compatibility John Herro
1996-02-22  0:00 ` Mark A Biggar
1996-02-23  0:00   ` PHILIP W. BRASHEAR
1996-02-23  0:00 ` Ken Garlington
1996-02-24  0:00   ` John Herro
1996-02-24  0:00     ` Robert Dewar
1996-02-26  0:00       ` Ken Garlington
1996-02-26  0:00         ` Robert Dewar
1996-02-26  0:00         ` Robert Dewar
1996-02-23  0:00 ` Peter Amey
1996-02-23  0:00 ` Keith Thompson

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