【问题标题】:Ada object "Train" cannot be used before end of its declaration在声明结束之前不能使用 Ada 对象“Train”
【发布时间】:2017-04-13 06:03:19
【问题描述】:

这段代码有什么问题?编译器说了两件事,没有 Run 条目并且 Run accept 与条目不匹配(两者似乎都是错误的),以及在声明之前不能使用 Train (但它已经被声明)。请向我解释发生了什么事。

我对展示整个代码犹豫不决,但可以这样做。

type ItineraryType is array (0..255) of Integer;
type Train is record
    Label : Integer;
    Capacity : Integer;
    Maxspeed : Integer;
    Starts : Integer;
    Itinerary : ItineraryType;
    Stops : Integer;
    lock : access Mutex;
end record;

task type TrainThread is
    entry Run (train1:Train);
end;
task body TrainThread is
    train : Train;
begin
    accept Run (train1:Train) do
        train := train1;
    end;
end;

-- part of main
train1 := new TrainThread;
train1.Run(trains(i));

main.adb:51:05: warning: no accept for entry "Run"
main.adb:52:17: object "Train" cannot be used before end of its declaration
main.adb:54:09: no entry declaration matches accept statement
gnatmake: "main.adb" compilation error

【问题讨论】:

    标签: concurrency syntax-error task ada


    【解决方案1】:

    Ada 不区分大小写,因此 trainTrain 是等价的。所以声明train : Train 将永远无效。 (诚​​然,在这种情况下,gnat 的信息可能会更好)

    【讨论】:

      猜你喜欢
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 2012-04-26
      • 1970-01-01
      • 2018-08-16
      • 2011-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多