How could one function influence the whole block non-executeable?

Jun 11, 2015 at 8:46am


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
		for(size_t i=0, I=C.size(); i<P.size(); ++i, ++I) {
			cout<<"P"<<i<<"0";
			P[i].resetCoefficient();
			cout<<"1";
			P[i].calculateCoefficient(cli, ec);//uvli=0; 2: there is only diffussion
			cout<<"2";
			B[I]=P[i].b;
			A(I, I)=P[i].aP;
			cout<<"3";
			for(size_t j=0; j<P[i].CI.size(); ++j) {
				A(I, P[i].CI[j])=P[i].a[j];
			}
			for(size_t j=0; j<P[i].PI.size(); ++j) {
				A(I, P[i].PI[j]+C.size())=P[i].ap[j];
			}
			cout<<"4"<<endl;
		}



Like I have this code. If I remove the bad function, the whole block run through, while if I bring it back, the whole block is not executed. 01234, none of these numbers printed out. This way, I cannot even find which line in the bad function is not working.

Please save me, this is driving me crazy! Thanks.
Last edited on Jun 11, 2015 at 8:51am
Jun 11, 2015 at 10:26am
line 1: A for loop has 3 terms, initialization, termination and increment. You have four terms. I am surprised this even compiles.
for(size_t i=0, I=C.size(); i<P.size(); ++i, ++I)

What is i<P.size() supposed to be? Is it supposed to be part of the termination condition? It's the third term, but is clearly not an increment.


Last edited on Jun 11, 2015 at 1:47pm
Jun 11, 2015 at 10:40am
@AbstractionAnon
The head of the for loop is just fine. Note the use of ,.

@northfly
What is the 'bad function'?

You need to check whether you have an index that is out of bounds. If you write out of bounds the stack may get corrupted and it is undefined what happens then.
Jun 11, 2015 at 12:37pm
If the loop isn't executing after you call the bad function then the loop condition is probably false. In other words, after executing the bad function, I suspect that P.size() <= 0. Try printing out P.size() just before the loop, or examine it in a debugger.
Jun 11, 2015 at 1:47pm
@coder777

Oops. I saw the second comma, but not the first.
Topic archived. No new replies allowed.