我正在研究标准的Ada POSIX 绑定,以及GNAT的Florist实现。目的是评估遗留应用程序是否可以从它自己使用的 C POSIX 函数的编译指示导入移植到使用标准绑定。最终目标是能够在不更改源代码的情况下在 Solaris 和 Linux 中重新编译应用程序。我的疑问是 UNIX 传统中用于进程间通信功能的几组接口,如信号量、消息队列等。 Florist 正在导入这些 C 函数:
当应用程序导入这些其他集合时: - 信号量:semget semop semctl - 消息队列:msgctl msgrcv msgsnd
一些来源将应用程序使用的集合定义为 System V 而不是 POSIX,而在其他来源中,它们被IEEE Std 1003.1-2001声明为标准化,这显然是 POSIX。
我的问题是:
我正在编写一个程序,掷两个骰子,并使用一组计数器来显示每个总数显示的次数。我的代码编译良好并且确实运行,但由于某种原因,前两个计数器从未增加,并且似乎按数字升序打印 - 对我来说,这听起来像是我的随机数函数的问题。但我不太明白我哪里出了问题。它也永远不会迭代正确的次数,实际上大约是一半。这是我的代码。
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
-- procedure main - begins program execution
procedure main is
dice1, dice2, diceTotal : Integer;
type Count_Array is array(1 .. 11) of Integer;
intArray : Count_Array;
-- function returnRand - produces a random number and returns it
function returnRand return Integer is
type magicNumber is new Integer range 2 .. 12;
package Rand_Number is new Ada.Numerics.Discrete_Random(magicNumber);
use Rand_Number;
theNumber : magicNumber;
g : Generator;
begin
Reset(g);
theNumber …Run Code Online (Sandbox Code Playgroud) 我想在私有部分中定义的包的公共部分(原始名称已弃用)中重命名常量.我试过这个,但GNAT说:
完全不变的声明似乎为时已晚
package Sample is
type The_Type is private;
My_Constant : constant The_Type;
My_Renamed_Constant : The_Type;
private
type The_Type is ...;
My_Constant : constant The_Type := ...;
My_Renamed_Constant : The_Type renames My_Constant;
end Sample;
Run Code Online (Sandbox Code Playgroud)