comp.lang.ada
 help / color / mirror / Atom feed
From: csampson@inetworld.net (Charles H. Sampson)
Subject: Re: Does Ada support endiannes?
Date: Mon, 12 Dec 2011 09:07:24 -0800
Date: 2011-12-12T09:07:24-08:00	[thread overview]
Message-ID: <1kc5n51.ffg0umddufyfN%csampson@inetworld.net> (raw)
In-Reply-To: 53n2sd7edt5i.1boh4452h0aks.dlg@40tude.net

Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:

> On Mon, 12 Dec 2011 04:46:22 -0800 (PST), Gerd wrote:
> 
> > On 12 Dez., 12:27, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> > wrote:
> > 
> > Any suggestion on how to convert, others than using "/" and "mod"?
> 
> Why not to use them? It would be a bad idea trying to avoid them.
> 
> It won't give you much performance, because memory mapping would require
> unpacking, alignment, checksum evaluation, stuff which would turn into
> extra copying. So why not just:
> 
>    type Octet is new Unsigned_8;
>    type Word is new Unsigned_16;
>    type Octet_Array is array (Positive range <>) of Octet;
> 
>    procedure Get_Little_Endian (Data : Octet_Array; Index : in out Integer;
>       Value : out Word) is -- No extra copying
>    begin
>       Value := Word (Data (Index)) + Word (Data (Index + 1)) * 256;
>       Index := Index + 2;
>    end Get_Little_Endian;
> 
> ...

     Don't you think this approach obscures what's going on, Dmitry,
thereby negating one of the design goals of Ada?  Sure, most of us who
have bit-twiddled in the bad old days can figure out what's going on, or
at least convince ourselves that we've figured out what's going on, but
I much prefer the clarity of something like

   type Single_Precision is -- old IBM single-precision
      record
         Negative : Boolean;
         Characteristic : Seven_Bit_Integer;
         Mantissa : Twenty_Four_Bit_Fixed_Point;
      end record;

   A_Variable : Single_Precision;

   ...

   A_Variable := (
      Negative => ...
      Characteristic => ...
      Mantissa => ...);

     LIke you, I've worked on a hard real-time system that had to
interface with hardware having a lot of different protocols and
interfaces.  My experience was that worries about code efficiency were
more apparent than real.

                        Charlie

P. S. Please forgive any errors in the syntax of my example.  I don't
have a compiler available to check them with.

P. P. S. I don't advocate the style of the above assignment statement. I
used the first newline only to retain control of the column alignment.
In a reasonable development system, I'd let the editor handle that for
me.
-- 
[A certain TV newsreader] had a role to play: presenter of the Other
Side of the Argument, to whom fair-minded people were obligated to
pay heed, no matter what nonsense he spouted.
Charlie Pierce, Idiot America



  reply	other threads:[~2011-12-12 17:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12  8:57 Does Ada support endiannes? Gerd
2011-12-12  9:23 ` Niklas Holsti
2011-12-12 11:27 ` Dmitry A. Kazakov
2011-12-12 12:44   ` Gerd
2011-12-12 19:23     ` Jeffrey Carter
2011-12-13 14:25       ` Gerd
2011-12-13 14:19     ` Gautier write-only
2011-12-14 16:16       ` Gerd
2011-12-14 18:16         ` Dmitry A. Kazakov
2011-12-14 20:16         ` Gautier write-only
2011-12-15 11:27           ` Gerd
2011-12-15 13:01             ` Simon Wright
2011-12-15 13:37             ` Dmitry A. Kazakov
2011-12-15 20:12             ` Jeffrey Carter
2011-12-12 12:46   ` Gerd
2011-12-12 13:22     ` Dmitry A. Kazakov
2011-12-12 17:07       ` Charles H. Sampson [this message]
2011-12-12 18:33         ` Dmitry A. Kazakov
2011-12-14  5:19           ` Charles H. Sampson
2011-12-14  8:56             ` Dmitry A. Kazakov
2011-12-14  9:46               ` Simon Wright
2011-12-15  9:14               ` Charles H. Sampson
2011-12-15  9:46                 ` Dmitry A. Kazakov
2011-12-25 21:42                   ` Charles H. Sampson
2011-12-26 10:47                     ` Dmitry A. Kazakov
2011-12-27 10:38                       ` Georg Bauhaus
2011-12-27 12:35                         ` Dmitry A. Kazakov
2012-01-04  4:33                       ` Charles H. Sampson
2012-01-04 11:56                         ` Dmitry A. Kazakov
2011-12-12 13:33     ` Robert A Duff
replies disabled

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