From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Using Posix with Apex
Date: 1997/01/29
Date: 1997-01-29T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-ya023280002901970740590001@news.ni.net> (raw)
In-Reply-To: 32ee8e2c.1005715@NEWS.CLOUD9.NET
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;
>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 is
not an Ada "problem."
Use declare blocks to hold intermediate values, especially for the result
of a function that returns an unconstrained array. (Just remember: in Ada
83 you have to declare the object as a constant; this rule went away in Ada
95.)
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271
next prev parent reply other threads:[~1997-01-29 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 [this message]
1997-01-30 0:00 ` Dr. Peter E. Obermayer
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