Re: Bug in g++'s int constructor?
Re: Bug in g++'s int constructor?
- Subject: Re: Bug in g++'s int constructor?
- From: Shawn Erickson <email@hidden>
- Date: Thu, 28 Mar 2002 17:50:28 -0800
I don't think in this case the compiler does any initialization of
variables or is expected to do so. It is luck that it works the first
time at all. You should be getting a waring about using an uninitialized
variable (unless you have warning turned off).
In other words I don't think this is a bug in the compiler but in your
code. It should be "int sum = 0;".
-Shawn
On Thursday, March 28, 2002, at 05:06 PM, Mark wrote:
Well that's what I had to do get the program running so I could pass it
in. It just made tracking down the problem with my CS prof. frustrating
for us both, since we both made assumptions that this was implemented
correctly. It isn't a major flaw, but it should still be fixed. I was
just curious as to if anyone has filled a bug report about this...
Am I off base on this? As far as I'm concerned compiler consistency is
a good thing. Especially if Apple wants Unix source to be ported over
to OS X without causing too high of an aggravation factor, where these
types of assumptions may be made ( as far as I know our digital unix
server we use for compiling at school has no trouble with this ).
- Mark.
On Thursday, March 28, 2002, at 07:42 PM, Phillip Morelock wrote:
now maybe i'm being stupid, but
why don't u just
int sum = 0;
??
cheers
fillup
On 3/28/02 2:42 PM, "Mark" <email@hidden> wrote:
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.
_______________________________________________
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.
_______________________________________________
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.