comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.de>
Subject: Re: Using fwrite in Ada
Date: Wed, 10 Aug 2005 19:28:07 +0200
Date: 2005-08-10T19:27:53+02:00	[thread overview]
Message-ID: <42fa3919$0$6966$9b4e6d93@newsread2.arcor-online.net> (raw)
In-Reply-To: <dddbut$7qm$1@newsm1.svr.pol.co.uk>

Makhno wrote:

> Does anybody have any idea as to how I get binary data onto stdout?

Use Streams and the 'Write and 'Read attributes of the type used
for binary data.

Here is a possible output part, it gets binary data onto stdout.
For the input part, use the 'read attribute where the text uses
the 'write attribute.


with Ada.Text_IO.Text_Streams;

procedure binio is

   use Ada.Text_IO;

   type Byte is mod 2**8;
   for Byte'size use 8;  -- just to make sure

   type Binary_Data is array(Natural range <>) of Byte;
     -- the type used for storing binary data internally

   stuff: Binary_Data(1..10);

   destination: Text_Streams.Stream_Access;

begin
   destination := Text_Streams.Stream (standard_output);
   Binary_Data'write(destination, stuff);
end binio;

If you just want to write integers, records (structs) etc.
to standard_output, use the 'Write attributes of the respective
types. That's what they are for. (No need to "cast" something.)



  reply	other threads:[~2005-08-10 17:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-10 17:01 Using fwrite in Ada Makhno
2005-08-10 17:28 ` Georg Bauhaus [this message]
2005-08-10 18:05 ` Martin Krischik
2005-08-11 17:01 ` tmoran
2005-08-11 21:59   ` Jeffrey Carter
replies disabled

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