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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,50b41333767ba40f X-Google-Attributes: gid103376,public From: "Dr. Peter E. Obermayer" Subject: Re: Using Posix with Apex Date: 1997/01/30 Message-ID: <32F0FD1F.4FF3@cci.de>#1/1 X-Deja-AN: 213198084 distribution: world references: <32ee8e2c.1005715@NEWS.CLOUD9.NET> content-type: text/plain; charset=us-ascii organization: Competence Center Informatik GmbH mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 2.0 (Win16; I) Date: 1997-01-30T00:00:00+00:00 List-Id: Matthew Heaney wrote: > > In article <32ee8e2c.1005715@NEWS.CLOUD9.NET>, pvanbell@cloud9.net (Paul > Van Bellinghen) wrote: > > >Output_File_Name.Name := > > Posix.To_String (Posix.Value > > (Posix_Process_Environment.Argument_List, 2)); > > If you don't know the length of the string returned by a function, then in > Ada 83 just declare the object as a constant in some dynamic scope: > > declare > The_Name : constant POSIX_String := > POSIX.Value (POSIX_Process_Environment.Argument_List, 2); > begin > Output_File_Name.Name (1 .. The_Name'Length) := > POSIX.To_String (The_Name); > end; > This solution assumes, that the Length of Output_File_Name.Name equals the length of The_Name. A POSIX_String may have a different length than the Ada-String, to which it is converted by POSIX.To_String, since individual characters might get expanded in two or more characters by this translation. (POSIX 1003.5b Chapt. 2.4.3.2). The following should do better, assuming that Output_file_Name.Name is always big enough for The_File_Name : declare The_File_Name: constant String:= Posix.To_String (Posix.Value (Posix_Process_Environment.Argument_List, 2)); begin Output_File_Name.Name(1..The_File_Name'Length) := The_File_Name; end; > >however, I kept getting an "invalid argument" exception when the code > >was executed. I called the Rational support team and found out that > >the line suld read > > > > Output_File_Name.Name > > (1 .. Posix.To_String > > (Posix.Value (Posix_Process_Environment.Argument_List, 2))' > > Length) := > > Posix.To_String (Posix.Value > > (Posix_Process_Environment.Argument_List, 2)); > > Rational gave you some bad advice. Please don't write code like this: > you're calling the function twice, and it's completely unreadable. This generally good advice is here not applicaple due to the reasons I gave above. The solution of RATIONAL also avoids the mentioned problems. < further interesting remarks deleted > > > -------------------------------------------------------------------- > Matthew Heaney > Software Development Consultant > > (818) 985-1271 -- Dr. Peter E. Obermayer Tel. : xx49-(0)5931 805-469 Fax : xx49-(0)5931 842-46 E-Mail: obermayer@cci.de _/_/_/ _/_/_/ _/_/_/ Competence Center Informatik GmbH _/ _/ _/ Lohberg 10 _/ _/ _/ D-49716 Meppen _/_/_/ _/_/_/ _/_/_/ http://www.cci.de/