From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.0 required=3.0 tests=BAYES_20,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a05:620a:24c9:b0:6ee:d791:9f84 with SMTP id m9-20020a05620a24c900b006eed7919f84mr22931424qkn.490.1666607479298; Mon, 24 Oct 2022 03:31:19 -0700 (PDT) X-Received: by 2002:a05:622a:15c7:b0:39b:2791:cd44 with SMTP id d7-20020a05622a15c700b0039b2791cd44mr26404928qty.676.1666607479160; Mon, 24 Oct 2022 03:31:19 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 24 Oct 2022 03:31:18 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=94.31.101.23; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf NNTP-Posting-Host: 94.31.101.23 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: 2-dimensional view on 1 dimensional array From: AdaMagica Injection-Date: Mon, 24 Oct 2022 10:31:19 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:64548 List-Id: Your code looks rather ununderstandable to me. A quick attempt on what you claimed you are trying to do (no guarantee): generic type T is private; type T_Array is array (Integer range <>) of T; package Dim1_to_2 is -- type T_Array_2Dim is array (Integer range <>, Integer range <>) of T; procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T) with Pre => Row in 1 .. Num_Row and Col in 1 .. Num_Col and Num_Row * Num_col = TA'Length; end Dim1_to_2; package body Dim1_to_2 is type T_Array_2Dim is array (Integer range <>, Integer range <>) of T; procedure Set (TA: in T_Array; Row, Num_Row, Col, Num_Col: Positive; Value: T) is TA2: T_Array_2Dim (1 .. Num_Row, 1 .. Num_Col); for TA2'Address use TA'Address; begin if Num_Row * Num_Col /= TA'Length or Row not in 1 .. Num_Row or Col not in 1 .. Num_Col then raise Constraint_Error; end if; TA2 (Row, Col) := Value; end Set; end Dim1_to_2; with Dim1_to_2; procedure Ausprobieren is type A is array (Integer range <>) of Integer; X: aliased A (-10 .. 10) := (others => 0); package To_2D is new Dim1_to_2 (Integer, A); begin To_2D.Set (X, Row => 2, Num_Row => 7, Col => 1, Num_Col => 3, Value => -1); for V of X loop Put_Line (V'Image); end loop;