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-Thread: 103376,782d6c8a12248b09 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada Recursion with strings References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1222813482 12.201.97.213 (Tue, 30 Sep 2008 22:24:42 GMT) NNTP-Posting-Date: Tue, 30 Sep 2008 22:24:42 GMT Organization: AT&T ASP.att.net Date: Tue, 30 Sep 2008 22:24:42 GMT Xref: g2news1.google.com comp.lang.ada:2175 Date: 2008-09-30T22:24:42+00:00 List-Id: Joe wrote: > > function IP_String (Word : Word_Type; > IP_String : String := "") return String > is > return IP_String( Word / 2**8, > "." & Sub_String & IP_String); > 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? This is a misleading error msg. Your problem is that your function IP_String has a parameter of the same name. Within the function, IP_String refers to the parameter. Thus, return IP_String (...); is interpreted as indexing into the String. Since "Word / 2 ** 8" is of type Word_Type and String is indexed by Integer, you get the error msg about expecting Integer. Though you can refer to the function IP_String within itself as Ip_Packet.IP_String, it would be better to change the name of the parameter to something other than the name of the function, like Current_Result. How many times does the magic number 2 ** 8 appear in this short example? -- Jeff Carter "I unclog my nose towards you." Monty Python & the Holy Grail 11