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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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 09:29:07 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!wn4feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3B24F26E.E198252C@worldnet.att.net> From: James Rogers X-Mailer: Mozilla 4.76 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: converting - adasockets References: <20010611.085009.1789366143.627@zamek.gda.pl> <3b2498c9$1_2@Newsfeeds.com> <3B24AF5D.241C9743@Physik.Uni-Magdeburg.DE> <3B24EB7A.D2792E53@worldnet.att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Mon, 11 Jun 2001 16:29:07 GMT NNTP-Posting-Host: 12.86.34.16 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 992276947 12.86.34.16 (Mon, 11 Jun 2001 16:29:07 GMT) NNTP-Posting-Date: Mon, 11 Jun 2001 16:29:07 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:8555 Date: 2001-06-11T16:29:07+00:00 List-Id: 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