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 X-Google-Thread: 103376,51e0e3232c45c76c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-06-11 04:45:39 PST Message-ID: <3B24AF5D.241C9743@Physik.Uni-Magdeburg.DE> Date: Mon, 11 Jun 2001 13:45:33 +0200 From: Gerald Kasner Organization: Uni Magdeburg X-Mailer: Mozilla 4.77 [de] (X11; U; Linux 2.4.2-2smp i686) 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> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Original-NNTP-Posting-Host: kasner.nat.uni-magdeburg.de NNTP-Posting-Host: loriot.cs.uni-magdeburg.de X-Trace: 11 Jun 2001 13:45:37 +0100, loriot.cs.uni-magdeburg.de Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!colt.net!news0.de.colt.net!news-fra1.dfn.de!news-koe1.dfn.de!RRZ.Uni-Koeln.DE!nntp.CS.Uni-Magdeburg.De!loriot.cs.uni-magdeburg.de!kasner.nat.uni-magdeburg.de Xref: archiver1.google.com comp.lang.ada:8534 Date: 2001-06-11T13:45:33+02:00 List-Id: "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 ? what about this ? ##################### with Ada.Text_IO; use Ada.Text_IO; procedure example is S : String (1 .. 10); I : Integer; begin S:=" 10"; I:=Integer'value(S); put(Integer'image(i)); New_Line; S:=" -1000"; I:=Integer'value(S); put(Integer'image(i)); New_Line; end example; -Gerald > first you would need to declare a String subtype having the same > length as the size of an Integer -- something like this: > > subtype Integer_Sized_String is String (1 .. Integer'size / Character'Size); > : > Then you would need to declare an unchecked conversion function, > something like this: > > with Ada.Unchecked_Conversion; > > function To_Integer is new Ada.Unchecked_Conversion > (Source => Integer_Sized_String, > Target => Integer); > > With these additional declarations, you can now do the conversion > like this: > > I := To_Integer (S (1 .. Integer_Sized_String'Length)); > > Now that this is done, I have a question for you -- assuming that > sizeof (int) on your machine is 4, what are you going to do with > the additional six characters of s? > > You may find it more useful to use the adasockets subprograms > using Stream_Element_Array parameters instead of the > string-oriented ones, because of their special treatment of CR and > LF characters. > > "Micha� Nowikowski" wrote in message > news:20010611.085009.1789366143.627@zamek.gda.pl... > > Hello > > > > Im writting a program which reads some data from a socket > > (i used adasockets). And i've problem with converting > > this date from String to fg Integer. How could i do that. > > In C it woul look like: > > > > char s[10]; > > int i; > > > > i = *(int*)s; > > > > but in Ada? > > > > thanks in advance > > Godfryd > > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- > http://www.newsfeeds.com - The #1 Newsgroup Service in the World! > -----== Over 80,000 Newsgroups - 16 Different Servers! =-----