首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Pragma包在数组上使用方面Default_Component_Value

使用Pragma包在数组上使用方面Default_Component_Value
EN

Stack Overflow用户
提问于 2022-01-16 16:59:02
回答 1查看 89关注 0票数 5

我用的是侏儒gcc 11.1,想知道是否有人能向我解释这种行为:

这是我的密码:

代码语言:javascript
复制
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真实真实的

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2022-01-16 18:42:58

我很抱歉地说,好像是个小虫子。

如果我显式地使用Default_Component_Value,则通过声明

代码语言:javascript
复制
   test : bool_arr := (others => <>);

所有组件都是True,正如预期的那样。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70732217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档