comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Ada Recursion with strings
Date: Tue, 30 Sep 2008 22:24:42 GMT
Date: 2008-09-30T22:24:42+00:00	[thread overview]
Message-ID: <KGxEk.366896$yE1.159169@attbi_s21> (raw)
In-Reply-To: <ff8b4b01-211b-4487-8184-85563f4148db@t42g2000hsg.googlegroups.com>

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



  parent reply	other threads:[~2008-09-30 22:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-30 20:30 Ada Recursion with strings Joe
2008-09-30 22:24 ` Adam Beneschan
2008-09-30 22:24 ` Jeffrey R. Carter [this message]
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