comp.lang.ada
 help / color / mirror / Atom feed
From: Gerald Kasner <Gerald.Kasner@Physik.Uni-Magdeburg.DE>
Subject: Re: converting - adasockets
Date: Mon, 11 Jun 2001 13:45:33 +0200
Date: 2001-06-11T13:45:33+02:00	[thread overview]
Message-ID: <3B24AF5D.241C9743@Physik.Uni-Magdeburg.DE> (raw)
In-Reply-To: 3b2498c9$1_2@Newsfeeds.com

"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" <godfryd@zamek.gda.pl> 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! =-----



  reply	other threads:[~2001-06-11 11:45 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 [this message]
2001-06-11 15:59     ` James Rogers
2001-06-11 16:29       ` James Rogers
2001-06-12  1:19         ` Ken Garlington
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