Illegal declaration in task definition

2019-07-29 03:23发布

问题:

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;