Weird branch test evaluation when using vector size()
Weird branch test evaluation when using vector size()
- Subject: Weird branch test evaluation when using vector size()
- From: Daniel Stenning <email@hidden>
- Date: Thu, 19 Mar 2009 14:48:19 +0000
- Thread-topic: Weird branch test evaluation when using vector size()
I have a vector of pointers to class "Buffer" declared in a class as
follows:
vector<Buffer*>* buff = new vector<Buffer*>;
I have code which tests the (nr of vector elements -1) to determine which of
two branches to take.
In the sample code below buff->size() is zero and thus
( buff->size() -1 ) should evaluate to -1 and the
- I am finding that if I evaluate (buff->size() -1 ) in the test shown
Below ( ie OPTION A) then executio incorrectly goers down PATH A instead of
PATH B ( buff->size()-1 = -1 thus -1 is less than I )
However if I assign buff->size() to a variable siz and then evaluate siz-1
As in OPTION B then executio goes down PATH B as I would expect.
What is going on ????
int I=0; // ( for example )
int siz = buff->size();
if ( ( buff->size() -1 ) >=i ) { // OPTION A
//if ( (siz -1) >=i ) { // OPTION B
(*buff)[i]= buf ; // BRANCH PATH A
}
else {
buff->push_back ( buf ) ; // BRANCH PATH B
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden