如何定义一个包含两个多维无约束数组的结构并将其传递给过程

问题描述 投票:0回答:2

我是 Ada 新手,所以我有一个问题:如何定义一个包含两个多维无约束数组的结构并将其传递给过程。 按照我写的代码:

package SDR_Treatment is
   
   -----------------------------------------------------------------------------
   --  CONSTANTS                                                               -
   -----------------------------------------------------------------------------
   
   GEO_SPACIAL_AND_SPEED: constant Natural :=  1;     --Type of Data
   
   -----------------------------------------------------------------------------

   type Slicing_Pointers is  array (Positive range <>) of Integer;
   type Region is array (Positive range <>, Positive range <>, Positive range <>) of Integer;
   
   type Location_and_Speed_Region is record
      
      Region_Id : Natural := 0;
      SP: Slicing_Pointers;
      Rig: Region;
      
   end record;
   
   procedure SDR_Encoding(lsr: in out Location_and_Speed_Region);
   

end SDR_Treatment;
-----------------------------------------------------------------------------

包体:

with Ada.Text_IO;         use Ada.Text_IO;

package body SDR_Treatment is
   
   procedure SDR_Encoding(lsr: in out Location_and_Speed_Rigion) is
--      lsr : rig;
   begin
    Ada.Text_IO.Put_Line("Encoding SDR...");
   end SDR_Encoding;
   
end SDR_Treatment;
_____________________________________________________________________________

这是我从编译器得到的错误

 C:\GNAT\2017\bin\src\sdr_treatment.ads
        18:11 unconstrained subtype in component declaration
        19:12 unconstrained subtype in component declaration
ada
2个回答
3
投票

正如编译器所说,您不能声明具有不受约束的子类型的记录组件。

您必须修复约束作为记录声明的一部分:

package SDR_Treatment is

   type Slicing_Pointers is array (Positive range <>) of Integer;
   type Region is array (Positive range <>,
                         Positive range <>,
                         Positive range <>) of Integer;

   type Location_and_Speed_Region (Low    : Positive;
                                   High   : Natural;
                                   X_Low  : Positive;
                                   X_High : Natural;
                                   Y_Low  : Positive;
                                   Y_High : Natural;
                                   Z_Low  : Positive;
                                   Z_High : Natural) is
      record
         Region_ID : Natural := 0;
         SP        : Slicing_Pointers (Low .. High);
         Rig       : Region (X_Low .. X_High,
                             Y_Low .. Y_High,
                             Z_Low .. Z_High);
      end record;

end SDR_Treatment;

0
投票

您应该将您的声明视为 C 数组

type Location_and_Speed_Region is record
    Region_Id : Natural := 0;
    SP: Slicing_Pointers;
    Rig: Region;
end record;

在这里,您尝试声明一条记录,其中静态组件的大小在编译时未知,这与声明几乎相同

struct {
  char int[];
};

如果您希望它更加“动态”,同时避免使用访问(即指针),请查看歧视记录

如果您喜欢使用动态分配的内存,请使用 access 类型

© www.soinside.com 2019 - 2024. All rights reserved.