From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ff63dd9ded39893d X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 29 Feb 2008 18:16:17 +0100 From: Georg Bauhaus Reply-To: rm.tsho+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Array Syntax References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <47c83de1$0$11006$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Feb 2008 18:16:17 CET NNTP-Posting-Host: 5f5e9d42.newsspool4.arcor-online.net X-Trace: DXC=6Rd>GYhJknE02Sh8E_NfIA4IUK ma740988@gmail.com wrote: > Trying to garner a feel for Ada - while perusing texts - and I'm > having slight difficulties understanding array syntax. > > > Max_Num : constant := 6; > > type Pixel_Data is > record > Num_Of_Values : Int32; > Is_Valid_Data : Boolean; > end record; > > type Pixel_Number is Int16 range 1 .. Max_Num ; > type Pixel_Data_Array is array > ( Pixel_Number range 1 .. Max_Num ) > of Pixel_Data; > > Pixel_Data_Array is an array 6 deep of composite type Pixel Data. So > far so good? Yes, though either Pixel_Number should be a "new Int16" or else a subtype of Int16. Below, you'll find an aggregate object of your anonymous array Buffer_Pixel_Data. The numbers in the leftmost column are index values of this type's index. D1: constant Pixel_Data := (Num_Of_Values => 42, Is_Valid_Data => true); D2: constant Pixel_Data := (Num_Of_Values => -666, Is_Valid_Data => false); begin Buffer_Pixel_Data := -- the first component of Buffer_Pixel_Data -- is an array of six, assigned one by one: (1 => Pixel_Data_Array'(1 => (0, True), 2 => (-1, false), 3 => (0, False), 4 => D2, 5 => D1, 6 => Pixel_Data'(D2)), -- the components of the array are records of type Pixel_Data -- the last one, at index 6, emphasizes -- using range 1 .. Max_Num for collectively setting values 2 | 4 => Pixel_Data_Array'(1 .. Max_Num => D2), -- explicitly mention the respective index type (as per Ludovic's -- remarks). The type of 6 is inferred by the compiler Int32'(6) => Pixel_Data_Array'(Pixel_Number'(1) .. 6 => D2), -- at index positions 3, 5, and 7 put an array with all -- components set to record value (1, True) 3 | 5 | 7 => Pixel_Data_Array'(others => (1, True)), -- you can indicate the range of index values by not using -- single index values, but the 'Range of the index type, 8 .. 9 => Pixel_Data_Array'(Pixel_Number'Range => D2), -- but it is sufficient to just name the index type 10 .. Frames_in_Buffer => Pixel_Data_Array'(Pixel_Number => D1)); -- the latter two work because of a coincidence: -- type Pixel_Number is new Int16 range 1 .. Max_Num ; -- and -- type Pixel_Data_Array is array -- ( Pixel_Number range 1 .. Max_Num ) ... have the same range constraint end News6;