comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Sequential_IO
Date: 1999/08/19
Date: 1999-08-19T00:00:00+00:00	[thread overview]
Message-ID: <H1Su3.10821$x04.623171@typ11.nn.bcandid.com> (raw)
In-Reply-To: 11f733ec.81e1abff@usw-ex0102-014.remarq.com


Shawn Barber <SbarberNOcqSPAM@snet.net> wrote in message
news:11f733ec.81e1abff@usw-ex0102-014.remarq.com...
> Ok, I forgot this last time. I'm working on NT4 with the
> GNAT3.11p compiler. Here are the peices of code which apply
> to this problem:
>
Well... actually, you did _not_ supply all of "the pieces of code which
apply to this problem."


However, I will make some assumptions (which I will state), and we'll
try to get to the bottom of this problem.

The fundamental error is that you have passed the NVM_Input_File_Name
string to One_Word_IO.Open.  Thus, the length of the filename passed
is whatever is the length of NVM_Input_File_Name (of which the declaration
is one piece of missing code).  You should have passed

NVM_Input_File_Name
  (NVM_Input_File_Name'First .. NVM_Input_File_Name'First +
Length_Of_NVM_Name - 1)

as the actual Name => parameter.

You did not supply the identification of Fixed.Move (e.g., by showing your
"use" clauses), so I assume this is Ada.Strings.Fixed.Move, -- in which case
the filename you passed has some number of trailing spaces.

A couple of other technical points:

  1.  You notice I used the 'First attribute in defining the slice of the
string
      to be passed.  This is always good practice when you don't know the
bounds
      of a string -- e.g., when inside a procedure which has a string out
mode
      (or in out mode) parameter. In other words, you _cannot_  assume the
first
      index of every string to be 1.

  2.  You assumed the equivalence of 'Last and the length of an array.  This
is
      only true if the array has a numeric index and the 'First attribute =
1.
      A better course is to actually use the 'Length attribute when what you
      want is the length.  When you deal with arrays having non-numeric
indices,
      'Last won't even be a number.  When writing a generic unit, for
example.
      in which an array index type is a generic formal parameter of type
(<>),
      whether the array index is numeric is not even known inside the
generic
      unit, so the distinction between index values and numeric attributes
such
      as 'Length is important.

One way to have avoided the use of Ada.Strings.Fixed.Move, and eliminated
altogether the need for the Get_Command_Line_Parameters procedure, yet
providing
the better readability of meaningful names for the command line parameters
would have been to use a renaming declaration, viz.:

   NVM_Input_File_Name : String renames Command_Line.Argument (1);

Then, you can pass the NVM_Input_File_Name argument directly to Open.

I realize this doesn't work with the optional debug file name, and the
supplying
of a default, but it's just another technique available in Ada.









  parent reply	other threads:[~1999-08-19  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-18  0:00 Sequential_IO Shawn Barber
1999-08-18  0:00 ` Sequential_IO Larry Kilgallen
1999-08-18  0:00 ` Sequential_IO Ted Dennison
1999-08-18  0:00 ` Sequential_IO Marin David Condic
1999-08-19  0:00 ` Sequential_IO Shawn Barber
1999-08-19  0:00   ` Sequential_IO Ted Dennison
1999-08-19  0:00   ` Sequential_IO Marin David Condic
1999-08-19  0:00   ` David C. Hoos, Sr. [this message]
1999-08-19  0:00 ` Sequential_IO Tucker Taft
1999-08-19  0:00   ` Sequential_IO Marin David Condic
1999-08-19  0:00   ` Sequential_IO Ted Dennison
1999-08-19  0:00     ` Sequential_IO Robert Dewar
1999-08-21  0:00     ` Sequential_IO Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox