From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: passing parametars as determinants
Date: Wed, 22 Oct 2014 09:57:16 -0600
Date: 2014-10-22T09:57:16-06:00 [thread overview]
Message-ID: <ttQ1w.331851$Ub6.154473@fx20.iad> (raw)
In-Reply-To: <4e918e9a-f2f1-4c9e-97ec-62b558d4621c@googlegroups.com>
On 10/22/2014 5:55 AM, compguy45@gmail.com wrote:
> task type myTaskType (a: Integer; b: Integer; c: access myOtherType);
>
>
> This is where i create tasks.....
>
>
> := new myTaskType(a=> i, b => j,c => access'myOtherType);
>
> I get compiler error "reserved word "access" cannot be used as identifier"
>
Here's an example of using an access discriminant in a task-type:
With
Ada.Text_IO;
procedure Test is
-- This is the type for the data to be passed to the task-type.
Type Info is array (positive range <>) of Integer;
-- The task-type's public interface.
Task Type Print_Task( Info_Param : not null access Info ) is
entry Print ( Index : in Positive );
entry Done;
end Print_Task;
-- The body of the task-type.
Task body Print_Task is
subtype Data_Range is Positive range Info_Param'Range;
Procedure Put( Index : Data_Range ) is
begin
Ada.Text_IO.Put_Line("Data(" & Integer'Image(Index) & " ) ->"
& ASCII.HT & Integer'Image(Info_Param(Index))
);
end Put;
-- Variable indicating if we're finished.
Finished : Boolean := False;
begin
loop
-- Select lets us accept things non-sequentially; A or B,
-- rather than A then B.
select
accept Done do
-- We're free to exit the task.
Finished:= True;
end Done;
or
accept Print (Index : in Positive) do
-- If the input is outside the range of the data, we print
-- an error-message, otherwise we desplay the indicated
data.
if Index not in Data_Range then
Ada.Text_IO.Put_Line("[ERROR] Index out of range.");
else
Put(Index);
end if;
end Print;
end select;
-- When Finished is flagged, we break out of the loop.
exit when Finished;
end loop;
Ada.Text_IO.Put_Line("Goodbye.");
end Print_Task;
-- This is the actual object of data we will pass to the task.
Data : aliased Info:= (8,3,-1,2);
-- The actual task.
SOME_TASK : Print_Task( Info_Param => Data'Access );
use Ada.Text_IO;
begin
SOME_TASK.Print(3);
SOME_TASK.Done;
-- Put_Line( "P(24) =" & P(K'Last)'Img );
end Test;
next prev parent reply other threads:[~2014-10-22 15:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 5:12 passing parametars as determinants compguy45
2014-10-22 5:16 ` compguy45
2014-10-22 5:22 ` Simon Wright
2014-10-22 11:55 ` compguy45
2014-10-22 12:39 ` Dennis Lee Bieber
2014-10-22 15:57 ` Shark8 [this message]
2014-10-22 6:11 ` mockturtle
2014-10-22 8:51 ` Georg Bauhaus
2014-10-22 17:25 ` Adam Beneschan
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox