From: Joe <joesmoe10@gmail.com>
Subject: Ada Recursion with strings
Date: Tue, 30 Sep 2008 13:30:14 -0700 (PDT)
Date: 2008-09-30T13:30:14-07:00 [thread overview]
Message-ID: <ff8b4b01-211b-4487-8184-85563f4148db@t42g2000hsg.googlegroups.com> (raw)
Hey all,
I'm trying to write a function that converts a 2**32 mod type into an
string formatted like an IP address (i.e. 192.168.2.1).
Here's what I wrote
with Ada.Text_IO;
use Ada.Text_IO;
procedure Ip_packet is
type Word_Type is mod 2**32;
function IP_String (Word : Word_Type;
IP_String : String := "") return String
is
Sub_String : String := Word_Type'Image(Word mod 2**8);
begin
if Word <= 2**8 then
return Word_Type'Image(Word) & IP_String;
else
return IP_String( Word / 2**8,
"." & Sub_String & IP_String);
end if;
end IP_String;
begin -- Ip_packet
Put(IP_String(123456));
end Ip_packet;
There are 2 errors with this that I don't understand. First, Ada
expects an integer for (word / 2**8). Is this because word_type is
outside the standard integer range? How do I get a division operator
that works on word_type?
If I patch the integer error by type casting word to an integer I get
another error. On the second return statement, Ada complains that
there are "too many subscripts in array reference". Is there a
limitation on the string I can pass to a recursive function call?
Thanks,
Joe
next reply other threads:[~2008-09-30 20:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 20:30 Joe [this message]
2008-09-30 22:24 ` Ada Recursion with strings Adam Beneschan
2008-09-30 22:24 ` Jeffrey R. Carter
2008-10-01 0:13 ` Joe
2008-10-01 0:27 ` Jeffrey R. Carter
2008-10-01 1:15 ` Robert A Duff
2008-10-01 11:34 ` Jeffrey R. Carter
2008-10-01 14:29 ` Adam Beneschan
2008-10-01 15:18 ` Jean-Pierre Rosen
2008-10-01 16:47 ` Georg Bauhaus
2008-10-02 7:24 ` Niklas Holsti
2008-10-02 8:18 ` Ludovic Brenta
2008-10-03 6:54 ` Maciej Sobczak
2008-10-03 7:38 ` Jean-Pierre Rosen
2008-10-03 9:06 ` Dmitry A. Kazakov
2008-10-01 0:28 ` Adam Beneschan
2008-10-01 9:48 ` Georg Bauhaus
2008-10-01 10:22 ` Dmitry A. Kazakov
2008-10-01 3:01 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox