comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Ada.Streams.Read Length Paramenter is not IN?
Date: Tue, 07 Aug 2001 19:48:24 GMT
Date: 2001-08-07T19:48:24+00:00	[thread overview]
Message-ID: <cCXb7.39349$Kd7.24285864@news1.rdc1.sfba.home.com> (raw)
In-Reply-To: slrn9mvbej.hs.lutz@taranis.iks-jena.de

> Ada.Streams.Read Length Parameter is not IN?
  Because Item'length tells how much data is wanted.  Last tells you,
as output, how much you actually got.  If you have a situation where
Last < Item'last does *not* mean EOF, but just means "that's all for
now", then you can use a loop to keep trying until it's all there.
  Next : Stream_Element_Offset := Item'first;
 ...
  while Next <= Item'last loop
    Read(F, Item(Next .. Item'last), Last);
    Next := Last+1;
  end loop;

> OTOH each T'Read or T'Input procedure exactly knows how many
> Storage_Elements are needed to fulfill the request. Why is this information
> not given to the Stream.Read procedure?
   It is.  Any time you pass as array as a parameter you implicitly
are also passing its 'first, 'last, 'length.

>  procedure Read(
>    Stream : in out Filedescriptor_Stream_Type;
>    Item   :    out Stream_Element_Array;
>    Last   :    out Stream_Element_Offset) is
>  begin
>     Item := Read (Stream);
>     Last := Item'Last;
>  end Read;
  This is unlikely to work.  Since your Read (Stream) always returns
an array of one element, assigning that to Item will only work if
Item is an array of one element.  The length of a particular
Stream_Element_Array is not dynamic.  That's why Last is there -
so you can see the length of the actual useful data portion of Item.



  parent reply	other threads:[~2001-08-07 19:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-07  9:02 Ada.Streams.Read Length Paramenter is not IN? Lutz Donnerhacke
2001-08-07 18:39 ` Ted Dennison
2001-08-07 20:18   ` Lutz Donnerhacke
2001-08-07 19:48 ` tmoran [this message]
2001-08-07 20:21   ` Lutz Donnerhacke
replies disabled

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