Re: Bug in g++'s int constructor?
Re: Bug in g++'s int constructor?
- Subject: Re: Bug in g++'s int constructor?
- From: Cliff Russell <email@hidden>
- Date: Thu, 28 Mar 2002 18:04:46 -0800
AFAIK what you described is not a bug with g++. It is not safe to use a
variable without initializing it. (I am pretty sure there aren't
constructors for primative types; chars, ints, floats and so on). In the
code you provided it is not safe to assume that sum will be initialized
to 0 before you use it, so the first line of your code needs to read int
sum = 0 to be correct.
Cliff
On Thursday, March 28, 2002, at 04:39 PM, cocoa-dev-
email@hidden wrote:
Message: 10
Date: Thu, 28 Mar 2002 17:42:37 -0500
Subject: Bug in g++'s int constructor?
From: Mark <email@hidden>
To: email@hidden
Hi everyone,
Please excuse me if this is off topic for this list, I really didn't
know where else to post it, aside for maybe darwin-dev or whatnot.
I believe I have inadvertently discovered a bug in g++. ( 2.95 I
believe, stock OS 10.1.3 with most recent dev tools installed )
The int constructor is only initializing an int to 0 in a member
function on the first run of that function. All calls to that function,
after the initial, get the SAME value that the int had when running the
member function the first time through.
i.e. this is what happened to me...
On the first run insert works perfectly, next time its called sum was
reallocated in the same spot with the same value every time. So the
program would hang, insert would never return true (ITEM was inserted)
because the sum of everything in the array + ITEM would ALWAYS be
greater then CAPACITY.
bool bag::insert( const int ITEM )
{
int sum;
for( x = 0; x <= ARRAY_INDEX; x++ )
{
sum += data[x];
}
if( (sum + ITEM) <= CAPACITY )
{
data[ ARRAY_INDEX ] = ITEM;
ARRAY_INDEX++;
return ( true );
}
else
return ( false );
}
Granted just changing int sum; to int sum = 0; fixes the problem, but
doesn't change the fact that this is a bug.
To the point, has anyone else discovered this? Filled a bug report?
Should I?
thanks for your time,
- Mark.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.