From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: Character/Integer Conversion
Date: 2000/04/03
Date: 2000-04-03T00:00:00+00:00 [thread overview]
Message-ID: <8cajks$d71$1@nnrp1.deja.com> (raw)
In-Reply-To: 8ca7k8$v2q$1@nnrp1.deja.com
In article <8ca7k8$v2q$1@nnrp1.deja.com>,
David C. Hoos, Sr. <david.c.hoos.sr@ada95.com> wrote:
> I do this all the time, in the following way:
> Msg : String (1 .. Length);
> type Msg_Bytes is array (Msg'Range)of
> Interfaces.C.Unsigned_Char;
> use type Interfaces.C.Unsigned_Char;
> Msg_Overlay : Msg_Bytes;
> for Msg_Overlay'Address use Msg'Address;
One more point about the above dubious code.
There is no guarantee that the declaration of Msg_Overlay
will not clobber the valeu in Msg. This probably will not
affect anything, but in other cases it can. It is probably
a good idea to always use a pragma Import (Ada, ..) for
the variable doing the overlaying to inhibit any default
initialization associated with the variable.
For example, in
x : integer := f (x);
y : access_to_integer;
for y'address use x'address;
the declaration of y will likely clobber the initial value
of x, and we should prevent that by either writing:
x : integer := f (x);
y : access_to_integer;
for y'address use x'address;
pragma Import (Ada, y);
or better by not using address overlays (an unchecked conversion
would be far safer and clearer in this situation).
Sent via Deja.com http://www.deja.com/
Before you buy.
next prev parent reply other threads:[~2000-04-03 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-03-31 0:00 Character/Integer Conversion ebresie
2000-04-02 0:00 ` DuckE
2000-04-03 0:00 ` David
2000-04-03 0:00 ` Robert Dewar
2000-04-04 0:00 ` Mats Weber
2000-04-05 0:00 ` Robert Dewar
2000-04-03 0:00 ` Robert Dewar [this message]
2000-04-04 0:00 ` Robert A Duff
2000-04-05 0:00 ` Robert Dewar
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox