Illegal declaration in task definition

半世苍凉 提交于 2020-01-06 01:45:14

问题


I have the following task specification:

with Ada.Real_Time; use Ada.Real_Time;

package pkg_task is
    task type task_t is
        activationTime : constant Integer := 1;
        period : constant Integer := 2;
        computingTime : constant Integer := 1;
        startingTime : Time;
    end task_t;
end pkg_task;

When I compile I obtain the error mentioned on the title in all the lines of the task specification where I declare the variables, and I don't know what is the problem.


回答1:


As Jacob wrote, you can't export anything that is not an entry in tasks. In this case, your task is really straightforward

package pkg_task is
   task type task_t;
end pkg_task;

In the body, you can then use your variables.

package body pkg_task is

   task body task_t is
      Activation_Time : constant Integer := 1;
      Period          : constant Integer := 2;
      Computing_Time  : constant Integer := 1;
      -- Starting_Time   : Time;
   begin
      null;
   end task_t;
end pkg_task;

Anyway, it would be easier if you explained us what you're trying to do.




回答2:


The interface to a task is its entries, so you only declare entries in a task specification. Any local variables in a task are declared in the declarative part of the task body.

A task without any entries is simply declared:

task Something;


来源:https://stackoverflow.com/questions/50103154/illegal-declaration-in-task-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!