* protected types in Ada95
@ 1997-09-07 0:00 SAD KAT
1997-09-10 0:00 ` Tucker Taft
1997-09-10 0:00 ` Tom Moran
0 siblings, 2 replies; 6+ messages in thread
From: SAD KAT @ 1997-09-07 0:00 UTC (permalink / raw)
Hi,
I have a program with differents tasks reading and writting data. I have
read that I have to protect my data to be sure that the values are the
correct ones, to keep a exclussive access to them.
I've done a think like that:
package data_pac is
type type_of_var is record
-- here are the description
end record;
protected type type_of_var_prot is
function read_var return integer;
procedure write_var (item : in type_of_var);
private
var2 : type_of_var;
end type_of_var_prot;
end data_pac;
package body data_pac is
protected type type_of_var_prot is
function read_var return integer is
begin
-- body of the function
end read_var;
procedure write_var (item : in type_of_var) is
begin
-- body of the procedure
end write_var;
end type_of_var_prot;
begin
null;
end data_proc;
The compiler shows that message : "subprogram body not allowed here"
and I don't knwo where's thw mistake. I have also another doubt, how
do I have to use the function read_var and the procedure write_var?
I mean, if I have in the main package:
procedure main is
data_a : type_of_var;
data_b : type_of_var_prot;
begin
get(data_a);
data_b.write_var(data_a);
-- rest of program
end main;
Is this correct?
Thanks for helping and please forgive my poor English,
mailto: sadkat@hotmail.com
mailto: aic001@teix.uib.es
Joan Andreu Juan Torrens (Illes Balears, SPAIN)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: protected types in Ada95
1997-09-10 0:00 ` Tucker Taft
@ 1997-09-10 0:00 ` Robert A Duff
1997-09-11 0:00 ` Robert Dewar
1 sibling, 0 replies; 6+ messages in thread
From: Robert A Duff @ 1997-09-10 0:00 UTC (permalink / raw)
Tucker, I thought you could parse Ada code in your head! ;-) ;-)
In article <EGArp1.H8K.0.-s@inmet.camb.inmet.com>,
Tucker Taft <stt@houdini.camb.inmet.com> wrote:
>SAD KAT (aic001@teix.uib.es) wrote:
>
>: Hi,
>: I have a program with differents tasks reading and writting data. I have
>: read that I have to protect my data to be sure that the values are the
>: correct ones, to keep a exclussive access to them.
>
>: I've done a think like that:
>
>: package data_pac is
>: type type_of_var is record
>: -- here are the description
>: end record;
>: protected type type_of_var_prot is
>: function read_var return integer;
>: procedure write_var (item : in type_of_var);
>: private
>: var2 : type_of_var;
>: end type_of_var_prot;
>: end data_pac;
>
>: package body data_pac is
>: protected type type_of_var_prot is
^^^^
You want "body" there, instead of "type".
>: function read_var return integer is
>: begin
>: -- body of the function
>: end read_var;
>: procedure write_var (item : in type_of_var) is
>: begin
>: -- body of the procedure
>: end write_var;
>: end type_of_var_prot;
>
>: begin
>: null;
>: end data_proc;
>
>
>: The compiler shows that message : "subprogram body not allowed here"
>: and I don't knwo where's thw mistake.
The compiler is seeing a subprogram body inside a protected type
declaration, which is illegal syntax.
>When you have a question like this, be sure to post the actual
>source code and the actual error message. The error message probably
>identified the exact line and column where the problem occurred.
>Without that information, we are just guessing.
>
>
>: I have also another doubt, how
>: do I have to use the function read_var and the procedure write_var?
>
>: I mean, if I have in the main package:
>
>: procedure main is
>: data_a : type_of_var;
>: data_b : type_of_var_prot;
>: begin
>: get(data_a);
>: data_b.write_var(data_a);
>: -- rest of program
>: end main;
>
>: Is this correct?
>
>Looks correct. You could use "read_var" as follows:
>
> data_a := data_b.read_var;
>
>: Thanks for helping and please forgive my poor English,
>
>De' nada. [Please forgive my poor Spanish!]
>
>: mailto: sadkat@hotmail.com
>: mailto: aic001@teix.uib.es
>
>: Joan Andreu Juan Torrens (Illes Balears, SPAIN)
>
>--
>-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
>Intermetrics, Inc. Burlington, MA USA
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: protected types in Ada95
1997-09-07 0:00 protected types in Ada95 SAD KAT
1997-09-10 0:00 ` Tucker Taft
@ 1997-09-10 0:00 ` Tom Moran
1997-09-11 0:00 ` Stephen Leake
1 sibling, 1 reply; 6+ messages in thread
From: Tom Moran @ 1997-09-10 0:00 UTC (permalink / raw)
Just for fun, there's an example use of protected types at
http://www.ionet.net/~timtroyr/funhouse/beer.html#ada
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: protected types in Ada95
1997-09-07 0:00 protected types in Ada95 SAD KAT
@ 1997-09-10 0:00 ` Tucker Taft
1997-09-10 0:00 ` Robert A Duff
1997-09-11 0:00 ` Robert Dewar
1997-09-10 0:00 ` Tom Moran
1 sibling, 2 replies; 6+ messages in thread
From: Tucker Taft @ 1997-09-10 0:00 UTC (permalink / raw)
SAD KAT (aic001@teix.uib.es) wrote:
: Hi,
: I have a program with differents tasks reading and writting data. I have
: read that I have to protect my data to be sure that the values are the
: correct ones, to keep a exclussive access to them.
: I've done a think like that:
: package data_pac is
: type type_of_var is record
: -- here are the description
: end record;
: protected type type_of_var_prot is
: function read_var return integer;
: procedure write_var (item : in type_of_var);
: private
: var2 : type_of_var;
: end type_of_var_prot;
: end data_pac;
: package body data_pac is
: protected type type_of_var_prot is
: function read_var return integer is
: begin
: -- body of the function
: end read_var;
: procedure write_var (item : in type_of_var) is
: begin
: -- body of the procedure
: end write_var;
: end type_of_var_prot;
: begin
: null;
: end data_proc;
: The compiler shows that message : "subprogram body not allowed here"
: and I don't knwo where's thw mistake.
When you have a question like this, be sure to post the actual
source code and the actual error message. The error message probably
identified the exact line and column where the problem occurred.
Without that information, we are just guessing.
: I have also another doubt, how
: do I have to use the function read_var and the procedure write_var?
: I mean, if I have in the main package:
: procedure main is
: data_a : type_of_var;
: data_b : type_of_var_prot;
: begin
: get(data_a);
: data_b.write_var(data_a);
: -- rest of program
: end main;
: Is this correct?
Looks correct. You could use "read_var" as follows:
data_a := data_b.read_var;
: Thanks for helping and please forgive my poor English,
De' nada. [Please forgive my poor Spanish!]
: mailto: sadkat@hotmail.com
: mailto: aic001@teix.uib.es
: Joan Andreu Juan Torrens (Illes Balears, SPAIN)
--
-Tucker Taft stt@inmet.com http://www.inmet.com/~stt/
Intermetrics, Inc. Burlington, MA USA
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: protected types in Ada95
1997-09-10 0:00 ` Tucker Taft
1997-09-10 0:00 ` Robert A Duff
@ 1997-09-11 0:00 ` Robert Dewar
1 sibling, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-09-11 0:00 UTC (permalink / raw)
<<: package body data_pac is
: protected type type_of_var_prot is
: function read_var return integer is
: begin
: -- body of the function
: end read_var;
: procedure write_var (item : in type_of_var) is
: begin
: -- body of the procedure>>
why are you declarting another protected type here, don't you mean to
be declarting the protected body. It is important to at least learn
how to read the syntax stuff in the RM!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: protected types in Ada95
1997-09-10 0:00 ` Tom Moran
@ 1997-09-11 0:00 ` Stephen Leake
0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 1997-09-11 0:00 UTC (permalink / raw)
Tom Moran wrote:
>
> Just for fun, there's an example use of protected types at
> http://www.ionet.net/~timtroyr/funhouse/beer.html#ada
Now that's a neat web site, and an excellent use of state-of-the art
programming :).
--
- Stephe
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1997-09-11 0:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-09-07 0:00 protected types in Ada95 SAD KAT
1997-09-10 0:00 ` Tucker Taft
1997-09-10 0:00 ` Robert A Duff
1997-09-11 0:00 ` Robert Dewar
1997-09-10 0:00 ` Tom Moran
1997-09-11 0:00 ` Stephen Leake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox