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 21:41:01 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn4feed!worldnet.att.net!135.173.83.71!wnfilter1!worldnet-localpost!bgtnsc06-news.ops.worldnet.att.net.POSTED!not-for-mail Message-ID: <3B259DF7.FB786846@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> <3B24F26E.E198252C@worldnet.att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Tue, 12 Jun 2001 04:41:00 GMT NNTP-Posting-Host: 12.86.32.128 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc06-news.ops.worldnet.att.net 992320860 12.86.32.128 (Tue, 12 Jun 2001 04:41:00 GMT) NNTP-Posting-Date: Tue, 12 Jun 2001 04:41:00 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:8595 Date: 2001-06-12T04:41:00+00:00 List-Id: Ken Garlington wrote: > > 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... > The Ada standard does not specify the size of an Integer. To do so would be to make Ada useless for general purpose embedded programming. A more general approach to memory overlays of strings and integers is as 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 Int_Bytes : constant Integer := Integer'Size / Character'Size; String_Rep : String(1..Int_Bytes); 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; Integer_Rep := Integer'Last; Ada.Text_Io.Put_Line("Integer_Rep:" & Integer'Image(Integer_Rep)); Ada.Text_Io.Put_Line("String_Rep: " & String_Rep); Integer_Rep := Integer'First; Ada.Text_Io.Put_Line("Integer_Rep:" & Integer'Image(Integer_Rep)); Ada.Text_Io.Put_Line("String_Rep: " & String_Rep); String_Rep := "This"; Ada.Text_Io.Put_Line("Integer_Rep:" & Integer'Image(Integer_Rep)); Ada.Text_Io.Put_Line("String_Rep: " & String_Rep); end Memory_Overlay; Note that the size of the string is calculated from the sizes of the Integer type and the Character type. Of course, it is still possible that a Character is 8 bits and an Integer is 34 bits, giving a bad result. The likelyhood of such an occurance is nearly zero. I do expect that an integer on a 64 bit machine may actually be 64 bits long. The above calculation will account for such a beast. Of course, the original poster wanted to convert data received over a socket connection. In this case the sending and receiving applications must have a common understanding of the data representations being transmitted. In that case, I would expect some static expression such as String(1..4) rather than testing for the local default size of an integer. I would also expect an integer definition such as: type socket_integer is range -2**32..(2**32 - 1); for socket_integer'size use 32; Jim Rogers Colorado Springs, Colorado USA