comp.lang.ada
 help / color / mirror / Atom feed
From: "Ken Garlington" <Ken.Garlington@computer.org>
Subject: Re: converting - adasockets
Date: Tue, 12 Jun 2001 01:19:18 GMT
Date: 2001-06-12T01:19:18+00:00	[thread overview]
Message-ID: <q6eV6.1715$yq.619409512@newssvr17.news.prodigy.com> (raw)
In-Reply-To: 3B24F26E.E198252C@worldnet.att.net

By the way, I couldn't find anything definitive in the Ada standard that
says String(1..4) is guaranteed to be 32 bits; although I admit it's usually
the case. I'd be interested in a description of why this would be considered
otherwise, since I've used one (Ada83) compiler where this wasn't the case.
Of course, there is definitely no guarantee that Integer is 32 bits; it
seems to me that an explicit type definition would be better here...


"James Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
news:3B24F26E.E198252C@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





  reply	other threads:[~2001-06-12  1:19 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
2001-06-12  1:19         ` Ken Garlington [this message]
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