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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,782d6c8a12248b09 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!wn11feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada From: anon@anon.org (anon) Subject: Re: Ada Recursion with strings Reply-To: no to spamers (No@email.given.org) References: X-Newsreader: IBM NewsReader/2 2.0 Message-ID: Date: Wed, 01 Oct 2008 03:01:01 GMT NNTP-Posting-Host: 12.65.168.190 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1222830061 12.65.168.190 (Wed, 01 Oct 2008 03:01:01 GMT) NNTP-Posting-Date: Wed, 01 Oct 2008 03:01:01 GMT Organization: AT&T Worldnet Xref: g2news2.google.com comp.lang.ada:7909 Date: 2008-10-01T03:01:01+00:00 List-Id: If your using GNAT. Checkout "GNAT.SOCKET.IMAGE" in file g-socket.adb. The "Image" routine converts the IP address (IPv4 and IPv6) to a string. Might give you some Ideas. In , Joe writes: >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