Reputation: 638
I have the following task body:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Task_Identification; use Ada.Task_Identification;
package body pkg_task is
task body task_t is
activationTime : Time_Span := 1; -- 1 second
period : Time_Span := 2; -- 2000 milliseconds
computingTime : Time_Span := 1; -- 1000 milliseconds
activeWaiting : Integer;
startingTime : Time;
begin
delay To_Duration(activationTime);
startingTime := Clock;
while (Clock - startingTime) < computingTime loop
activeWaiting := activeWaiting + 1;
Put_Line("Task(" & Image(Current_Task) & "): Internal variable: " & Integer'Image(activeWaiting));
if (period - (Clock - startingTime)) < computingTime then
delay To_Duration(period - (Clock - startingTime));
end if;
end loop;
end task_t;
end pkg_task;
When compiling, I obtained the mentioned error:
gcc-7 -c pkg_task.adb
pkg_task.adb:8:47: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:8:47: found type universal integer
pkg_task.adb:9:39: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:9:39: found type universal integer
pkg_task.adb:10:46: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:10:46: found type universal integer
The thing is that I am quite new in this language, and I do not understand much about it. In fact I find it a bit complex may I say, and I do not find much information around the Internet.
Upvotes: 0
Views: 610
Reputation: 1703
Since Time_Span is a private type, literals will not be automatically converted. Try:
To_Time_Span (1.0)
Also, since the parameter to To_Time_Span is a real type (a duration), you need the decimal part. Ada won't let you mix integers and real types without explicit conversions.
Upvotes: 3