From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,FROM_WORDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,51e0e3232c45c76c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-11 18:20:06 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!newscon01.news.prodigy.com!newsmst01.news.prodigy.com!prodigy.com!postmaster.news.prodigy.com!newssvr17.news.prodigy.com.POSTED!not-for-mail From: "Ken Garlington" Newsgroups: comp.lang.ada References: <20010611.085009.1789366143.627@zamek.gda.pl> <3b2498c9$1_2@Newsfeeds.com> <3B24AF5D.241C9743@Physik.Uni-Magdeburg.DE> <3B24EB7A.D2792E53@worldnet.att.net> <3B24F26E.E198252C@worldnet.att.net> Subject: Re: converting - adasockets Organization: ex-FlashNet, now Prodigy X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-Mimeole: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: NNTP-Posting-Host: 65.67.102.205 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr17.news.prodigy.com 992308758 6207069 65.67.102.205 (Mon, 11 Jun 2001 21:19:18 EDT) NNTP-Posting-Date: Mon, 11 Jun 2001 21:19:18 EDT Date: Tue, 12 Jun 2001 01:19:18 GMT Xref: archiver1.google.com comp.lang.ada:8590 Date: 2001-06-12T01:19:18+00:00 List-Id: 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" 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