comp.lang.ada
 help / color / mirror / Atom feed
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: <8cajeh$css$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;

That's a particularly nasty low level hacking solution. It is
inherently non-portable (the whole idea of the existence of
the C.Unsigned_Char type is that it might have a different
representation from Standard.Character), and it is a mistake
to use low level address overlay stuff when there is a perfectly
good solution.

Note also that the effect of address overlays itself is
implementation dependent, there is no requirement on a compiler
that this "work" right, since "working" is not defined in the
RM. In practice it probably wil work, though I would always
make such variables aliased if you absolutely have to use
address overlays.

In addition, it is usually better to use Unchecked_Conversion
than address overlays, since it is better defined, and the use
is flagged in the context clause. Address overlays are
definitely overused. Perhaps it was a mistake in Ada 95
to legitimize these (in Ada 83 they are erroneous, in Ada 95
implementation dependent).

Anyway, the advice in the other message (using the 'Pos
attribute) is a far better approach to your problem.

One more trouble with the above declarations is that there
is no guarantee that the address of an array is necessarily
the address of the first element. The above declarations
may simply result in overlaying dope vectors with peculiar
results!


Sent via Deja.com http://www.deja.com/
Before you buy.




  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     ` Robert A Duff
2000-04-05  0:00       ` Robert Dewar
2000-04-03  0:00   ` Robert Dewar [this message]
2000-04-04  0:00     ` Mats Weber
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