我正在尝试使用 mac 上的终端编译 ada,但总是收到此错误“错误:'-x ada' 中的值'ada'无效”有人知道如何解决此问题吗?
我试图理解与Adacore Libre版本一起提供的Gnat编译器与在Linux发行版或MinGw中使用gcc标准的编译器之间的根本区别.
我假设主要的区别可能是Adacore版本总是最新版本,而Linux版本的版本可能是在分发版本发布之日可用的版本.
但是还有功能上的差异吗?意味着Adacore版本中是否有任何改进的功能,他们不会发布到Gnu提供的一般开源版本?
我不是一个非常有经验的Linux用户,所以如果在Gnu /开源世界中有更多经验这是透明的,那么道歉,但我找不到任何关于此的内容.
不使用 nonstandard\xe2\x80\xa1 Scalar_Storage_Order 子句,如何通过记录表示子句结合任何其他语言功能的任意组合来可移植地表示 IPv4 标头,以便 \ xe2\x80\x9c相同的\xe2\x80\x9d 代码适用于小端和大端处理器,但以 IETF 称为网络字节的方式在线上发出(例如,通过以太网帧的有效负载) order(这是 IETF 对 big-endian 的奇特名称)。在 C 中,\xe2\x80\x9c相同的\xe2\x80\x9d 代码可以利用预处理器宏在小端处理器上执行字节交换,但在大端处理器上不执行任何操作,但标准 Ada 没有预处理器。在 C++ 中,\xe2\x80\x9c相同的\xe2\x80\x9d 代码可以利用元模板编程 (MTP) 在小端处理器上执行字节交换,但在大端处理器上不执行任何操作,但是标准 Ada 缺乏 MTP。
\n\n(顺便说一句,当大端处理器与小端外设 IC 的内存映射寄存器接口时,设备驱动程序中也会出现同样的问题,反之亦然:小端处理器与大端 IC 接口时的内存映射寄存器。)
\n\n BytesPerWord : constant := 4;\n BitsPerByte : constant := 8;\n PowerOf2Highest : constant := BytesPerWord*BitsPerByte - 1; -- part #1 of byte-swap\n type Header_IPv4 is record\n Version : integer range 0 .. F#16;\n IHL : integer range 0 .. F#16;\n TOS : integer …Run Code Online (Sandbox Code Playgroud) 我想知道在使用Ada代码时绑定和链接之间的根本区别是什么?我在谷歌上找不到一个好的解释,这就是为什么我问这个问题.
对于绑定过程,输入是什么,输出是什么?绑定和链接之间有什么关系?我认为首先需要进行绑定.
谢谢,波格丹.
Gnat 测试的文档展示了如何生成线束和框架单元测试。它为目标项目中的每个公共函数创建一个单元测试,但如果我添加另一个单元测试,那么当我重新生成线束和骨架单元测试时,该单元测试就会被覆盖。
在gnattest 提供的简单示例项目中,如何添加另一个测试?我试过了:
(1) 在已有的测试函数中添加另一个 Assert 行。这可行,但不是好的做法;第一个失败的测试会阻止其他测试的运行。
(2)向obj/gnattest/harness/gnattest.xml添加函数定义然后重新生成测试不起作用;xml 文件在用于创建测试存根之前会重新生成。
(3) 通过以下更改手动将定义添加到测试/和利用/,这些更改会因重新生成测试而受到破坏。
将其添加到 obj/gnattest/tests/simple-test_data-tests.ads:
procedure Test_Inc2_4f8b9f (Gnattest_T : in out Test);
Run Code Online (Sandbox Code Playgroud)
将其添加到 obj/gnattest/tests/simple-test_data-tests.adb:
-- begin read only
procedure Test_Inc2 (Gnattest_T : in out Test);
procedure Test_Inc2_4f8b9f (Gnattest_T : in out Test) renames Test_Inc2;
-- id:2.2/4f8b9f38b0ce8c74/Inc/1/0/
procedure Test_Inc2 (Gnattest_T : in out Test) is
-- simple.ads:7:4:Inc
-- end read only
begin
Assert (Inc(2) = 2, "this test should fail");
-- begin read only
end Test_Inc2;
-- …Run Code Online (Sandbox Code Playgroud) 我有一个实现许多功能的标记类型。在一种情况下,我需要这些功能之一来进入无限循环。不幸的是,据我所知,我没有办法对其进行编译,从而不会发出警告。我希望仍然使用-gnatwe以确保我的代码中没有警告,但是如何实现这种功能。
该函数如下所示:
function Foo (This : Some_Type) return Some_Type'Class is
begin
loop
Do_Useful_Stuff_Indefinitely_With (This);
end loop;
-- return This; (if needed?)
end Foo;
Run Code Online (Sandbox Code Playgroud)
我试过了,pragma (No_Return)但那仅适用于过程(并且该Foo函数在其他地方用作适当的函数,因此必须具有相同的签名)。
我也尝试过,pragma Suppress (All_Checks)但是仍然对代码无法到达或缺少返回语句错误提出警告。
有什么办法可以使一次性功能永久运行而不会发出警告?
我有以下用于网络协议实现的代码。由于协议是大端,我想使用Bit_Order属性和High_Order_First值,但似乎我犯了一个错误。
With Ada.Unchecked_Conversion;
with Ada.Text_IO; use Ada.Text_IO;
with System; use System;
procedure Bit_Extraction is
type Byte is range 0 .. (2**8)-1 with Size => 8;
type Command is (Read_Coils,
Read_Discrete_Inputs
) with Size => 7;
for Command use (Read_Coils => 1,
Read_Discrete_Inputs => 4);
type has_exception is new Boolean with Size => 1;
type Frame is record
Function_Code : Command;
Is_Exception : has_exception := False;
end record
with Pack => True,
Size => 8;
for Frame …Run Code Online (Sandbox Code Playgroud) 我正在开发一个巨大的代码包(主要是用 ada 编写的),这是一个极其混乱的情况。到目前为止,尚未应用任何单元测试,并且对于所有现有代码,不得实施单元测试。但我们的团队决定,所有新代码都应该与测试一起实现。在 GPS 中,可以让 GNATtest 自动生成项目中所有功能和程序的测试程序。但正如所写,我们必须从自动生成中排除所有旧代码。
有没有办法将函数和过程标记为“需要测试”?
我在动态和静态链接 Ada 中的库时遇到问题。我准备了一个最低限度的工作示例。这三个文件定义了一个输出“Hello world”的库:
helloworld_lib.gpr :
project Helloworld_Lib is
for Library_Name use "helloworld_lib";
for Source_Files use ("helloworld_lib.adb", "helloworld_lib.ads");
for Library_Kind use "static";
for Library_Dir use "obj";
end Helloworld_Lib;
Run Code Online (Sandbox Code Playgroud)
helloworld_lib.adb:
with Ada.Text_IO;
package body helloworld_lib is
procedure Hello is
begin
Ada.Text_IO.Put_Line("Hello world");
end Hello;
end helloworld_lib;
Run Code Online (Sandbox Code Playgroud)
helloworld_lib.ads:
with Ada.Text_IO;
use Ada.Text_IO;
package helloworld_lib is
procedure Hello;
end helloworld_lib;
Run Code Online (Sandbox Code Playgroud)
这两个文件定义了一个导入库并运行它的项目:
helloworld_interface.gpr :
with "helloworld_lib.gpr";
project Helloworld_Interface is
for Create_Missing_Dirs use "True";
for Main use ("helloworld_interface.adb");
for Source_Files use ("helloworld_interface.adb");
for …Run Code Online (Sandbox Code Playgroud) 我用几种语言(C、C++、Fortran77、Fortran90)编写了代码,并且可以使用 CMake 编译它,没有任何问题。效果很完美。
\n\n现在,我想在用 C 编写的 main() 中添加一些 Ada 函数,并且我想通过 CMake 编译它。鉴于我无法使用 CMake 将我的 Ada 函数链接到主函数,我得到
\n\nmain.c:(.text.startup+0x16a): undefined reference to adainit\nmain.c:(.text.startup+0x179): undefined reference to adafunction\nmain.c:(.text.startup+0x190): undefined reference to adafinal\nRun Code Online (Sandbox Code Playgroud)\n\n我通过使用主函数(用 C 编写)调用唯一的 Ada 函数(我编写了该函数)进行了另一个简化测试,并使用以下命令编译了它
\n\ngcc -c main.c\ngnatmake -c lib_ada.ali\ngnatbind -n lib_ada.ali\ngnatlink lib_ada.ali main.o -o exe\nRun Code Online (Sandbox Code Playgroud)\n\n效果很好。你知道我如何将这种方法集成到 CMakeList.txt 中吗?
\n\n注意:我认为(也许我错了)我不能使用唯一的 gnatlink,因为我需要链接我已经拥有的所有其他功能。
\n\n这里报告了一个最小的可重复示例。
\n\n--- main.c ---
\n\n#include <stdio.h>\n\nextern int adainit();\nextern int adafinal();\nextern int Add(int,int);\n\nint main()\n{\n adainit();\n printf ("Sum of 3 and 4 is: …Run Code Online (Sandbox Code Playgroud)