• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Weird branch test evaluation when using vector size()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird branch test evaluation when using vector size()


  • Subject: Re: Weird branch test evaluation when using vector size()
  • From: Daniel Stenning <email@hidden>
  • Date: Thu, 19 Mar 2009 15:55:47 +0000
  • Thread-topic: Weird branch test evaluation when using vector size()

Oops !  I think I got it - size_t isnt a signed type !!!


On 19/3/09 14:48, "Daniel Stenning" <email@hidden> wrote:

> 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

References: 
 >Weird branch test evaluation when using vector size() (From: Daniel Stenning <email@hidden>)

  • Prev by Date: Re: gcc and bitwise right shift
  • Next by Date: Re: Weird branch test evaluation when using vector size()
  • Previous by thread: Weird branch test evaluation when using vector size()
  • Next by thread: Re: Weird branch test evaluation when using vector size()
  • Index(es):
    • Date
    • Thread