comp.lang.ada
 help / color / mirror / Atom feed
From: Michael Moeller <mic2@t-online.de>
Subject: Re: xor
Date: Tue, 27 Mar 2012 21:09:02 +0100
Date: 2012-03-27T21:09:02+01:00	[thread overview]
Message-ID: <Pine.GSO.4.64.1203272029240.2819@kodiak1> (raw)
In-Reply-To: <9t99r9F6e2U1@mid.individual.net>



On Sun, 25 Mar 2012, Niklas Holsti wrote:

> On 12-03-25 18:16 , Michael Moeller wrote:
>> Thank you for your quick answer.
>> 
>> Can I use Unsigned_Byte_T to read in a byte from a file
>> as in C? I haven't looked into this yet.
>
> C has several ways to "read in a byte from a file", depending on the type of 
> the file and how you specify which byte you want to read. Can you be more 
> specific?

I have to read in what in C is called an unsigned byte, which in fact is
a stream of bytes without any interpretation as a symbol. Just a number
from 0 to 255.

In addition it would be nice to call something like 'fstat' to get the 
size of file in advance instead of checking every byte for EOF.

>
> If you mean reading an 8-bit octet from a "binary file" -- that is, not a 
> text file -- you can use the Ada library packages Ada.Sequential_IO or 
> Ada.Direct_IO, depending on your needs. These are generic packages, so you 
> must instantiate them for the type of data, for example Unsigned_Byte_T.
>
> If the file contains a mixture of different kinds of "binary" data, for 
> example both 8-bit data and 16-bit data, or more complex structures, you 
> should use the Ada "stream" facility from Ada.Streams.Stream_IO. The stream 
> facility helps you handle things like different endianness, padding, packing, 
> unusual encodings, and so on.
>
> The stream facility does not use generics; instead, it uses a combination of 
> tagged types and the special "stream attribute" operations T'Read, T'Write, 
> et cetera, which you can define differently for each type, T, that is present 
> in your file. For example, your 'Read operation for a 16-bit integer will 
> specify whether the integer is stored in little-endian or big-endian order in 
> the file (by reading two 8-bit integers, using 'Read for the 8-bit type, in 
> the corresponding order).
>
> The stream technique takes a bit of study to understand, but it works very 
> well, especially if the file has a mixture of different complex structures of 
> data, or if the file is created by a different language or computer and is 
> not in the "native" form for your Ada compiler.
>
> -- 
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
>      .      @       .
>
Perhaps it will be more save to leave the C-procedures alone and to
call them from within Ada instead. I don't know whether this will be 
easier. However, I'll give Sequential_IO and Direct_IO a try.

Regards,
Michael




  reply	other threads:[~2012-03-27 19:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-25 14:28 xor Michael Moeller
2012-03-25 14:01 ` xor Niklas Holsti
2012-03-25 15:16   ` xor Michael Moeller
2012-03-25 19:05     ` xor Dmitry A. Kazakov
2012-03-27 20:31       ` xor Michael Moeller
2012-03-25 19:26     ` xor Niklas Holsti
2012-03-27 20:09       ` Michael Moeller [this message]
2012-03-27 19:44         ` xor Dmitry A. Kazakov
2012-03-27 21:16           ` xor Michael Moeller
2012-03-27 21:14             ` xor Simon Wright
2012-03-27 22:56               ` xor Michael Moeller
2012-03-27 22:03             ` xor Georg Bauhaus
2012-03-27 23:50               ` xor Michael Moeller
     [not found]                 ` <bbedne9wdofZyu_SnZ2dnUVZ_hydnZ2d@earthlink.com>
2012-03-28 12:18                   ` xor Michael Moeller
2012-03-28 12:48                     ` xor Georg Bauhaus
2012-03-28 15:23                       ` xor Michael Moeller
2012-03-28 15:58                         ` xor Niklas Holsti
2012-03-28 17:28                           ` xor Michael Moeller
2012-03-28 23:25                           ` xor Randy Brukardt
2012-03-29  5:17                             ` xor Niklas Holsti
2012-03-29 23:41                               ` xor Randy Brukardt
2012-03-30 21:53                                 ` xor Niklas Holsti
     [not found]                         ` <jtmdnfjWWsUYoO7SnZ2dnUVZ_gSdnZ2d@earthlink.com>
2012-03-28 17:44                           ` xor Michael Moeller
2012-03-28 14:07                     ` xor Dmitry A. Kazakov
2012-03-28 16:16                       ` xor Michael Moeller
2012-03-28 16:08                         ` xor Dmitry A. Kazakov
2012-03-28 17:36                           ` xor Michael Moeller
     [not found]                             ` <tdadna1MV6uj5O7SnZ2dnUVZ_jidnZ2d@earthlink.com>
2012-03-28 21:48                               ` xor Georg Bauhaus
2012-03-29  7:43                               ` xor Dmitry A. Kazakov
2012-03-29  7:49                               ` xor Simon Wright
2012-03-27 21:28           ` xor Georg Bauhaus
2012-03-27 19:50         ` xor Randy Brukardt
2012-03-27 21:44           ` xor Michael Moeller
2012-03-27 22:01             ` xor Georg Bauhaus
2012-03-27 20:13         ` xor 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