comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: converting - adasockets
Date: Mon, 11 Jun 2001 05:17:49 -0500
Date: 2001-06-11T05:17:49-05:00	[thread overview]
Message-ID: <3b2498c9$1_2@Newsfeeds.com> (raw)
In-Reply-To: 20010611.085009.1789366143.627@zamek.gda.pl

Assuming the following Ada declarations,
S : String [1 .. 10];
I : Integer;

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! =-----



  parent reply	other threads:[~2001-06-11 10:17 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. [this message]
2001-06-11 11:45   ` Gerald Kasner
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