From: "Dr. Peter E. Obermayer" <obermaye@cci.de>
Subject: Re: Using Posix with Apex
Date: 1997/01/30
Date: 1997-01-30T00:00:00+00:00 [thread overview]
Message-ID: <32F0FD1F.4FF3@cci.de> (raw)
In-Reply-To: mheaney-ya023280002901970740590001@news.ni.net
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
> <mailto:matthew_heaney@acm.org>
> (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/
next prev parent reply other threads:[~1997-01-30 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-01-28 0:00 Using Posix with Apex Paul Van Bellinghen
1997-01-29 0:00 ` Matthew Heaney
1997-01-30 0:00 ` Dr. Peter E. Obermayer [this message]
1997-02-10 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox