comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: GNAT Ada.Streams Bug?
Date: Mon, 29 Nov 2004 07:50:28 GMT
Date: 2004-11-29T07:50:28+00:00	[thread overview]
Message-ID: <8xAqd.413508$wV.119785@attbi_s54> (raw)
In-Reply-To: LKJpd.59640$Ro.2237800@news20.bellglobal.com

>All kinds of possibilities are available when _you_ control the format.
  Anytime you need a certain external form you should plan on writing
your own 'Read et al.  It may happen to work out that the default
routines supplied by the compiler do what you want, but that shouldn't
be your starting assumption.  Things with odd sizes likely won't work,
and composite objects will be inefficient.  If you use a record rep
clause to allow you to do IO on a multibyte object, you ought to write
your own 'Read et al for that object.  eg:

    for Partition_Type use
       record
          Flags          at 0 range 0..7;
          CHS_Start      at 1 range 0..23;
          Kind           at 4 range 0..7;
          CHS_End        at 5 range 0..23;
          LBA_Start      at 8 range 0..31;
          LBA_Size       at 12 range 0..31;
       end record;

  subtype External_Partition_Type
    is Ada.Streams.Stream_Element_Array(1 .. Partition_Type'size/8);
  function Internalize is new Ada.Unchecked_Conversion
    (Source=>External_Partition_Type, Target=>Partition_Type);
  function Externalize is new Ada.Unchecked_Conversion
    (Source=>Partition_Type, Target=>External_Partition_Type);

    procedure Partition_Type_Read
                (Stream : access Ada.Streams.Root_Stream_Type'class;
                 Item   : out Partition_Type) is
        External : External_Partition_Type;
        Last : Ada.Streams.Stream_Element_Offset;
    begin
        Read(Stream.all, External, Last);
        if Last /= External'last then
            raise ...
        end if;
        Item := Internalize(External);
    end Partition_Type_Read;

    for Partition_Type'Read use Partition_Type_Read;

IMHO



  parent reply	other threads:[~2004-11-29  7:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-25 17:41 GNAT Ada.Streams Bug? Warren W. Gay VE3WWG
2004-11-25 19:40 ` Jeff C r e e.m
2004-11-26  4:11   ` Warren W. Gay VE3WWG
2004-11-26  9:49     ` Georg Bauhaus
2004-11-26 17:30       ` Warren W. Gay VE3WWG
2004-11-27  7:34         ` Martin Krischik
2004-11-28  1:10           ` Warren W. Gay VE3WWG
2004-11-29  7:50         ` tmoran [this message]
2004-11-29 17:47           ` Warren W. Gay VE3WWG
2004-11-26 22:47     ` Simon Wright
2004-11-27 14:42       ` Warren W. Gay VE3WWG
2004-11-27 17:25         ` 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