comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Examining individual bytes of an integer
Date: Mon, 15 Oct 2018 15:27:41 -0500
Date: 2018-10-15T15:27:41-05:00	[thread overview]
Message-ID: <pq2t7t$iuc$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 4f2fb3ba-9cca-46ad-b970-ccbcb7d08a2c@googlegroups.com

"Matt Borchers" <mattborchers@gmail.com> wrote in message 
news:4f2fb3ba-9cca-46ad-b970-ccbcb7d08a2c@googlegroups.com...
> Does anybody ever do this kind of thing?

Yes, and they should be drawn-and-quartered. :-)

> procedure Main is
>
>   type Byte is mod 256;
>   type Word is mod 2 ** 32;
>
>   type E2 is array(1 .. 4) of Byte;
>
>   Z: Word;
>   Y: E2;
>   for Y'Address use Z'Address;

This sort of thing either destroys optimization (if it choses to pay 
attention to it) or destroys your code (if it doesn't). In particular, 
Z'Address is not required to be meaningful for objects that aren't aliased 
or by-reference (which Z is not above). (See 13.3(16).) Z might get placed 
into a register or optimized away completely, in which case Z'Address 
references nothing.

You could of course declare Z as aliased:

    Z : aliased Word;

but then you're guarenteeing worse code than you would get from one of the 
other methods. (Address clauses are almost always implemented with a level 
of indirection, because of their potentially dynamic nature.)]

                                     Randy.



  parent reply	other threads:[~2018-10-15 20:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-14 19:15 Examining individual bytes of an integer Henrik Härkönen
2018-10-14 19:55 ` Jeffrey R. Carter
2018-10-14 21:28   ` Niklas Holsti
2018-10-15 10:18     ` AdaMagica
2018-10-15 18:43       ` Niklas Holsti
2018-10-15 20:18         ` Randy Brukardt
2018-10-16 10:18           ` AdaMagica
2018-10-16 11:55             ` Dmitry A. Kazakov
2018-10-16 22:35               ` Randy Brukardt
2018-10-17  8:10                 ` Dmitry A. Kazakov
2018-10-17  9:47                   ` briot.emmanuel
2018-10-17 10:04                     ` Dmitry A. Kazakov
2018-10-17 21:57                   ` Randy Brukardt
2018-10-16 22:33             ` Randy Brukardt
2018-10-17  6:51               ` Niklas Holsti
2018-10-17 22:01                 ` Randy Brukardt
2018-10-17  8:17               ` Dmitry A. Kazakov
2018-10-17 22:03                 ` Randy Brukardt
2018-10-17 22:10                 ` Randy Brukardt
2018-10-18  8:01                   ` Dmitry A. Kazakov
2018-10-18  9:33               ` AdaMagica
2018-10-18 21:18                 ` Randy Brukardt
2018-10-19  6:27                   ` Niklas Holsti
2018-10-19  8:28                     ` AdaMagica
2018-10-19 16:38                       ` Niklas Holsti
2018-10-14 21:04 ` Niklas Holsti
2018-10-15  7:49   ` Niklas Holsti
2018-10-15  8:55   ` Simon Wright
2018-10-15 10:52   ` Björn Lundin
2018-10-14 23:42 ` Matt Borchers
2018-10-14 23:45   ` Matt Borchers
2018-10-15  9:02     ` Simon Wright
2018-10-15  7:29   ` Dmitry A. Kazakov
2018-10-15  9:05   ` Simon Wright
2018-10-15 16:11     ` Simon Wright
2018-10-15 20:27   ` Randy Brukardt [this message]
2018-10-15  5:37 ` Henrik Härkönen
2018-10-15  7:42 ` Dmitry A. Kazakov
replies disabled

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