__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)
我一直在看的参考资料:
我正在实例化一个带有枚举的通用包,以访问多个值之一并在子程序重载中使用。我想要一个定义明确的、编译时检查过的值集,我可以使用和查找。
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)