小编MtR*_*oad的帖子

将字符串常量或文字传递给 Ada 中的 GCC 内置函数

__builtin_cpu_is我之前在 GNAT 中使用过一些内在函数,但在尝试传递以下内容时出现错误Chars_Ptr

error: parameter to builtin must be a string constant or literal
Run Code Online (Sandbox Code Playgroud)

我还尝试直接插入“amd”目标参数,但这不起作用。

with Ada.Text_IO;
with Interfaces.C.Strings;

procedure Intrinsics is
   procedure CPU_Init;
   pragma Import (Intrinsic, CPU_Init, "__builtin_cpu_init");

   function Is_CPU (CPU_Name : Interfaces.C.Strings.chars_ptr) return Interfaces.C.Int;
   pragma Import (Intrinsic, Is_CPU, "__builtin_cpu_is");
   
   Target : constant Interfaces.C.Strings.Chars_Ptr := Interfaces.C.Strings.New_String ("amd");
begin
   CPU_Init;

   -- ERROR from the below line, from Is_CPU
   Ada.Text_IO.Put_Line (Interfaces.C.Int'Image (Is_CPU (Target)));
end Intrinsics;
Run Code Online (Sandbox Code Playgroud)

我一直在看的参考资料:

ada

6
推荐指数
2
解决办法
254
查看次数

在 Ada 中将空枚举传递给泛型的惯用方法

我正在实例化一个带有枚举的通用包,以访问多个值之一并在子程序重载中使用。我想要一个定义明确的、编译时检查过的值集,我可以使用和查找。

generic
    -- Different types because we don't want to ensure we never put
    -- beer in a wine class, or wine in a beer stein.  Our inventory
    -- never changes, for... reasons.
    type Wine is (<>);
    type Beer is (<>);
package Bar is
    type Wine_Glass is null record;
    type Beer_Stein is null record;

    -- Unopened cases/bottles of each.
    type Wine_Inventory is array (Wine) of Natural;
    type Beer_Inventory is array (Beer) of Natural;

    procedure Pour (G : in out Wine_Glass; …
Run Code Online (Sandbox Code Playgroud)

ada ada2012

2
推荐指数
1
解决办法
97
查看次数

标签 统计

ada ×2

ada2012 ×1