由于Random(Generator, First, Last)是在运行时实现的,GNAT允许以下代码,但它不是Ada2012的一部分。我可以导致一个编译错误,因为它应该是不可用的?
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
procedure Main is
package Positive_Random is new Ada.Numerics.Discrete_Random
(Result_Subtype => Positive);
Generator : Positive_Random.Generator;
-- This should fail, since function isn't part of Ada 2012.
Value : Positive := Positive_Random.Random (Generator, 1, 10);
begin
Put_Line (Value'Image);
end Main;这是我的gpr文件:
project Default is
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Main use ("main.adb");
package Compiler is
for Switches ("ada") use ("-gnat12");
end Compiler;
end Default;发布于 2021-08-01 08:16:43
在我看来,the standard way要做这件事就是添加a global restriction
pragma Restrictions (No_Implementation_Identifiers);No_Implementation_Identifiers
没有用法名称表示具有语言定义的包或语言定义的泛型包实例中出现的实现定义的标识符的声明。
但这在GNAT Community Edition 2021年中不起作用(我猜在GCC 11中也不起作用)。
您可以创建一个自定义的GNAT运行时并删除此子程序,或者使用aspect Implementation_Defined标记它以使限制生效。
https://stackoverflow.com/questions/68605628
复制相似问题