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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,9f5373f7d078262 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Length & Last Attributes. Date: 1998/10/13 Message-ID: #1/1 X-Deja-AN: 400455327 Sender: matt@mheaney.ni.net References: <6vtr9b$hp9$1@platane.wanadoo.fr> NNTP-Posting-Date: Mon, 12 Oct 1998 18:35:23 PDT Newsgroups: comp.lang.ada Date: 1998-10-13T00:00:00+00:00 List-Id: "BARDIN Marc" writes: > How to get corrects values for Length & Last attributes for a string > AFTER it has been defined in the program ? > In the following example program, these 2 attributes aren't corrects after > Max_Descripteur value is known. procedure Op (S : in String) is begin ... S'First ... ... S'Last ... ... S'Length ... > > Anticipated thanks. > Marc > > > with Text_Io; use Text_Io; > procedure Test_Tri_Fichier is > > Max_Descripteur : Positive; > subtype Ch_L_Cha�ne is String (1..Max_Descripteur); The rule is "linear elaboration." The problem is that you elaborate the subtype Ch_L_Chane using object Max_Descipteur, which hasn't been given a value! So your subtype will have some value for T'Last, but who knows what it will be? The solution is to elaborate the subtype AFTER giving Max_Descripteur a value. > Fin_Sc : Positive range Ch_L_Cha�ne'range; > package Ent_Es is new Text_Io.Integer_Io (Integer); > > begin > Max_Descripteur := 5; Now declare your subtype: declare subtype Ch_L_Chane is String (1 .. Max_Descripteur); begin ... Ch_L_Chane'Length ... ... Ch_L_Chane'Last ... > Put (" Length : "); Ent_Es.Put (Ch_L_Cha�ne'Length, 5); > Fin_Sc := Ch_L_Cha�ne'Last; > Put (" Fin_Sc : "); Ent_Es.Put (Fin_Sc, 5); > end Test_Tri_Fichier;