Ada在数组上使用方面Default_Component_Value,带有Pragma Pack



我正在使用gnat gcc 11.1,想知道是否有人能向我解释这种行为:

这是我的代码:

with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
pragma Ada2012;
procedure Hello is
type bool_arr is array (Integer range 1 .. Integer'Size) of Boolean with
Default_Component_Value => True;
pragma Pack (bool_arr);
test : bool_arr;
procedure P is
idx   : String           := "index ";
strg  : Unbounded_String := To_Unbounded_String (idx);
strg2 : Unbounded_String;
begin
for I in test'range loop
Append (strg, I'Image);
Append (strg2, " " & test (I)'Image);
end loop;
Put_Line (To_string (strg));
Put_Line (To_String (strg2));
end P;
begin
P;
end Hello;

正如我得到的:

你好,世界!索引1 2 3 4 5 6 8 9 11 12 13 14 15 16 17 18 1920 21 22 23 24 25 27 28 29 30 31 32真-真-假-假真假真假假假假假假假假

这不是我想要的,通过设置with Default_Component_Value => True

如果我注释掉Pragma Pack(bool_arr),那么我得到的是:

你好,世界!索引1 2 3 4 5 6 7 8 9 11 12 13 14 16 17 18 19 20 21 22 23 25 26 28 29 30 31 32真实真实真实真实真实真实真实真实真实真实真实真实

感谢您的帮助。

很抱歉,看起来像是GNAT中的一个错误。

如果我通过声明明确使用Default_Component_Value

test : bool_arr := (others => <>);

所有组件均为True。

相关内容

最新更新