Ada程序可在Linux中运行,但不能在GPS Windows 10中运行 [英] Ada program works in Linux but not in GPS Windows 10

查看:117
本文介绍了Ada程序可在Linux中运行,但不能在GPS Windows 10中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此先感谢您的帮助。我目前正在从事ada编程的一些初学者工作,并且已经从 http:/安装了GNAT编程工作室(GPS) /libre.adacore.com/download/configurations#
我有Windows 10 64位。在学校给我以下代码:

Thanks in advance for any help. I am currently doing some beginner work on ada programming and I have installed GNAT Programming Studio (GPS) from http://libre.adacore.com/download/configurations# I have Windows 10 64-bits. I was given the following code at school:

pragma Task_Dispatching_Policy(FIFO_Within_Priorities);

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;

procedure PeriodicTasks is

    Start : Time;

    package Duration_IO is new Ada.Text_IO.Fixed_IO(Duration);
    package Int_IO is new Ada.Text_IO.Integer_IO(Integer);

    task type T(Id: Integer; Period : Integer) is
        pragma Priority(Id);
    end;

    task body T is
        Next : Time;
        X : Integer;
    begin
        Next := Start;
        loop
            Next := Next + Milliseconds(Period);
            -- Some dummy function
            X := 0;
            for Index in 1..5000000 loop
                X := X + Index;
            end loop;
            Duration_IO.Put(To_Duration(Clock - Start), 3, 3);
            Put(" : ");
            Int_IO.Put(Id, 2);
            Put_Line("");
            delay until Next;
        end loop;
    end T;

    -- Example Task
    Task_P10 : T(10, 250);
    Task_P12 : T(12, 500);
    Task_P14 : T(14, 500);
    Task_P16 : T(16, 250);
    Task_P18 : T(18, 500);
    Task_P20 : T(20, 250);
begin
    Start := Clock;
    null;
end PeriodicTasks;

我在GPS中打开文件,将其构建(无错误)并运行,但没有显示所有打印输出。我听说有时您会遇到多核CPU的问题,因此每次打开gps.exe时,CPU亲缘关系都设置为仅一个CPU,并且始终以管理员身份运行。但是,这也不起作用,我没有输出。
我决定使用Oracle Virtual Box并设置仅具有一个处理器的Ubuntu OS(32位)。安装了用gnatmake编译的GNAT工具,并使用./periodictasks运行,然后猜猜是什么,该程序执行了应做的工作并打印出了信息。

I opened the file in GPS, built it (no errors) and ran it but it doesn't show any printed output. I have heard that sometimes you get issues with multicore CPUs, so everytime the gps.exe is opened, the CPU affinity is set to only one CPU and it is always "Run as Administrator". However, this did not work either, I get no output. I decided to use Oracle Virtual Box and set up an Ubuntu OS (32 bits) with only one processor. Installed the GNAT tools, compiled with gnatmake, ran with ./periodictasks, and guess what, the program did what it is supposed to do and printed out the info.

之后这么长的故事,有人知道为什么会这样吗?会是64位还是32位的情况?

After all this long story, does anybody know why this is happening? Could it be a 64 bit vs 32 bit situation?

非常感谢!

推荐答案

直到最近,GNAT都默认不检查整数溢出。它确实检查了约束错误,例如将0分配给 Positive

Until recently, GNAT didn't check for integer overflow by default. It did check for constraint errors, e.g. assigning 0 to a Positive.

我们很多人认为这对编译器开发人员来说是一个奇怪的选择,因为它引发了许多问题,其根本原因是无法处理整数溢出。最近的变化使我们假设开发人员现在同意了!

Many of us thought this was a strange choice by the compiler developers, because it led to many questions whose root cause was failure to handle integer overflow. The recent change leads us to suppose that the developers now agree!

您的问题是由于以下语句引起的

Your problem arises because of the statement

for Index in 1..5000000 loop
   X := X + Index;
end loop;

最终将以X〜10 ^ 13表示,不适合32位整数(它可以容纳64位整数,但是在大多数(即使不是全部)GNAT平台上也可以是 Long_Long_Integer )。

which would end up with X ~ 10^13, which doesn’t fit in a 32-bit integer (it would fit in a 64-bit integer, but that would be a Long_Long_Integer on most if not all GNAT platforms).

您的Windows编译器可能是GNAT GPL 2016,它显示了新的行为,而Ubuntu编译器是较旧的FSF GCC。

It’s likely that your Windows compiler is GNAT GPL 2016, which shows the new behaviour, while the Ubuntu compiler is an older FSF GCC.

您的Windows编译器使用编译器开关 -gnato0 使用旧的行为。

You can tell your Windows compiler to use the old behaviour using the compiler switch -gnato0.

您可以告诉Ubuntu编译器执行以下操作:使用新行为,使用编译器开关 -gnato

You can tell your Ubuntu compiler to use the new behaviour using the compiler switch -gnato.

要获取有关任务中未处理的异常的异常消息(否则会默默地死掉),您可以添加

To get an exception message on unhandled exceptions in tasks (which otherwise die silently), you can add

GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Unhandled_Raise);

在主程序开始时。

这篇关于Ada程序可在Linux中运行,但不能在GPS Windows 10中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆