预期的私有类型 "Ada.Real_Time.Time_Span"

Expected private type "Ada.Real_Time.Time_Span"

我有以下任务正文:

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;

编译时出现上述错误:

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

问题是我对这门语言还很陌生,对它了解不多。事实上,我可能会说它有点复杂,而且我在 Internet 上没有找到太多信息。

由于Time_Span是私有类型,文字不会自动转换。尝试:

To_Time_Span (1.0)

此外,由于 To_Time_Span 的参数是实数类型(持续时间),因此您需要小数部分。 Ada 不允许您在没有显式转换的情况下混合使用整数和实数类型。