This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strange problem with "plus-equals"


Hello,

Having a problem with "+=" operator (and the addition / assignment operation in
general) in g++.

I have a protected function that looks like:

double LSMbdnew::norm(double *vec1, long num)	{
	long i;
	double a, ret;
	ret = 0.0;
	for (i=0; i<num; i++)	{
		a = *(vec1 + i);
		ret = ret + a*a;
	}
	return ret;
}

Problem is, the variable ret becomes zero after the second iteration in the test
I'm running.  How does this happen?  I have checked the variable ret -- there is
no conflict in this scope.  In fact, if I change the last line in the loop to a
straight assignment, there's no problem.  But when I try to use assign/add,
problem.

Thanks,
-David


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]