我用的是侏儒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 10 11 12 14 16 16 17 18 19 20 21 22 24 24 26 27 28 29 30 31 32真假真假假
通过设置with Default_Component_Value => True,这不是我想要的。
如果我注释掉了Pragma Pack(bool_arr),那么我得到了以下内容:
你好,世界!指数1 2 3 4 5 6 7 8 10 11 12 13 16 16 17 18 19 20 22 24 24 26 27 28 29 30 31 32真实真实的
谢谢你的帮助。
发布于 2022-01-16 18:42:58
我很抱歉地说,好像是个小虫子。
如果我显式地使用Default_Component_Value,则通过声明
test : bool_arr := (others => <>);所有组件都是True,正如预期的那样。
https://stackoverflow.com/questions/70732217
复制相似问题