comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam@spam.com>
Subject: Re: New to Ada, noticing something strange.
Date: Fri, 30 Sep 2005 06:06:31 GMT
Date: 2005-09-30T06:06:31+00:00	[thread overview]
Message-ID: <HB4%e.4883$zQ3.3939@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <1128038313.717692.268490@z14g2000cwz.googlegroups.com>

mike.martelli@gmail.com wrote:

> 		charMap: array (Character) of Integer;

You have undefined elements of this array, and may well be referencing them. You 
should probably initialize all of them:

type Char_Mapping is array (Character) of Integer;

Char_Map : Char_Mapping :=
('0' => 0, '1' => 1, '2' => 2, ... 'F' => 15, others => -16);

> 		NumOfArgs, size, carry: Integer := 0;

By making these Integer, you're implying that negative values are meaningful. 
These should probably be Natural. Size should probably be Positive.

> 				size := Length(operand1);

Why are you using a global variable here? Especially since it doesn't seem to be 
referenced anywhere else?

> 				when others => return strChar(1);

when others =>
    return Strchar (Strchar'First);

> 			--converts all lowercase characters to uppercase

Ada.Characters.Handling.To_Upper, as you noted elsewhere.

> 				if charMap(To_String(operand1)(i)) >= charMap(charBase) then

Here you can be referencing uninitialized values of Charmap, since the program 
has no control over the arguments it receives.

> 			for i in reverse 1 .. ResultSize(operand1,operand2) loop
> 				digit := AddDigits(To_String(operand1)(i), To_String(operand2)(i));

One of these strings may be shorter than the result of Resultsize, and when you 
try to index it with that value (first time through the loop), this should raise 
Constraint_Error.

So, what inputs did you run this with, and what output did you obtain?

-- 
Jeff Carter
"There's no messiah here. There's a mess all right, but no messiah."
Monty Python's Life of Brian
84



  parent reply	other threads:[~2005-09-30  6:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-29 17:20 New to Ada, noticing something strange mike.martelli
2005-09-29 18:39 ` Jeffrey R. Carter
2005-09-29 19:05   ` mike.martelli
2005-09-29 22:25     ` Randy Brukardt
2005-09-29 23:58       ` mike.martelli
2005-09-30  0:28         ` mike.martelli
2005-09-30  6:06         ` Jeffrey R. Carter [this message]
2005-09-30  6:28         ` Jeffrey R. Carter
2005-09-30 10:19         ` Georg Bauhaus
2005-09-30 16:43           ` mike.martelli
2005-09-30  6:23     ` Jeffrey R. Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox