comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Help with Copying Shared Memory to Local
Date: 24 May 2002 16:54:08 -0400
Date: 2002-05-24T21:01:02+00:00	[thread overview]
Message-ID: <uznypjmhb.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: EE1B58C60CD7D9ED.3DE0D594451AD094.92104DC9322C357A@lp.airnews.net

"John R. Strohm" <strohm@airmail.net> writes:

> type x is record
>     csr: byte;
>     dr: byte;
> end record;
> for x use record at mod 2;
> for x'size use 16;
> 
> Or something of that nature.

This says that objects of type x are 16 bits in size, and located on
16 bit boundaries.

If we have the following code:

declare
   a : X;
   b : X;
begin
   a := b;
end;

The compiler is perfectly free to do two 8 bit copies. On an 8 bit
machine, that's what I'd expect!

Now consider this:

declare
   a : X;
   b : X;
   c : X;
   d : X;
begin
   a := b;
   c := d;
end;

The compiler is perfectly free to do one 32 bit copy. On a 32 bit
machine, that's what I'd hope for (not quite expect :).

Most compilers, most of the time, will do what you want. But it is
_not_ _guarranteed_ by the language.


Where I really got bit by this the first time was using a bit-mapped
rep spec to access the bits in a hardware register, which is the
natural way to do it in Ada. The compiler happily coded 8 bit accesses
to get to the bits it needed, and the hardware got thoroughly
confused. The only way to get it right was to use machine code to do a
16 bit read to normal RAM, then unchecked convert to the bit-mapped
rep spec. Then bit or byte access to the RAM copy was fine.

-- 
-- Stephe



  parent reply	other threads:[~2002-05-24 20:54 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-23 13:50 Help with Copying Shared Memory to Local John Cupak
2002-05-23 20:32 ` Jeffrey Carter
2002-05-23 21:18   ` John Cupak
2002-05-24  1:37     ` Randy Brukardt
2002-05-24  2:08       ` Jeffrey Carter
2002-05-24 17:05         ` John R. Strohm
2002-05-24 16:55           ` Stephen Leake
2002-05-24 20:43             ` John R. Strohm
2002-05-24 19:49               ` Pat Rogers
2002-05-24 23:23                 ` martin.m.dowie
2002-05-24 20:54               ` Stephen Leake [this message]
2002-05-24 19:41           ` Jeffrey Carter
2002-05-26  0:55           ` John Cupak
2002-05-28 17:52             ` John Cupak
2002-05-25 11:23   ` Robert Dewar
2002-05-26  4:48     ` Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2002-05-24 14:22 Beard, Frank [Contractor]
2002-05-24 19:30 ` 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