From: James Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: converting - adasockets
Date: Mon, 11 Jun 2001 16:29:07 GMT
Date: 2001-06-11T16:29:07+00:00 [thread overview]
Message-ID: <3B24F26E.E198252C@worldnet.att.net> (raw)
In-Reply-To: 3B24EB7A.D2792E53@worldnet.att.net
James Rogers wrote:
>
> Gerald Kasner wrote:
> >
> > "David C. Hoos, Sr." schrieb:
> > >
> > > Assuming the following Ada declarations,
> > > S : String [1 .. 10];
> >
> > This is not an Ada declaration ! (Pascal,Modula-2,Oberon-2...??)
> >
> > > I : Integer;
> > >
> > Why unchecked conversion ?
>
> Unchecked Conversion is necessary because the data is not a string
> representation of an integer, but an integer value returned as
> a string. For instance, if the integer is represented as 32 bits,
> the string will be returned as a four byte string. Those four bytes
> need to be interpreted as an integer instead of as a string.
>
> Ada provides two approaches for solving this problem.
>
> The first is to use unchecked conversion as described by Mr.
> Hoos. The second is to define a string and an integer to occupy
> the same address. Simply copy the string from Adasockets into
> the overlayed string, then read the value as an integer.
>
> The C code example used by the original poster showed the C
> equivalent of viewing a string as an integer. There was no conversion
> of values as would occur using the 'value attribute.
A simple example of defining an integer and a string to occupy the
same address follows:
-- Coversion between String and Integer when the string merely contains
-- the bit pattern for the integer, not the character representation
-- of the integer.
--
with Ada.Text_Io;
procedure Memory_Overlay is
String_Rep : String(1..4);
Integer_Rep : Integer;
Num : Integer;
for String_Rep'Address use Integer_Rep'Address;
begin
Num := 0;
while Num < 1024 loop
Integer_Rep := Num;
Ada.Text_Io.Put_Line("Integer_Rep:" & Integer'Image(Integer_Rep));
Ada.Text_Io.Put_Line("String_Rep: " & String_Rep);
Num := Num + 100;
end loop;
end Memory_Overlay;
Jim Rogers
Colorado Springs, Colorado USA
next prev parent reply other threads:[~2001-06-11 16:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-11 6:50 converting - adasockets
2001-06-11 9:22 ` Gerald Kasner
2001-06-11 10:17 ` David C. Hoos, Sr.
2001-06-11 11:45 ` Gerald Kasner
2001-06-11 15:59 ` James Rogers
2001-06-11 16:29 ` James Rogers [this message]
2001-06-12 1:19 ` Ken Garlington
2001-06-12 4:41 ` James Rogers
2001-06-11 16:33 ` tmoran
2001-06-18 17:13 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox