VS2010 - Is this a bug?

Discussion in 'C++' started by VBNick, Sep 10, 2010.

  1. VBNick

    VBNick New Member

    Joined:
    Sep 10, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I was trying to make a for loop count down backwards using this loop, but when it gets to zero, instead of realizing that decrementing will bring the number below zero, it tries to make the unsigned short (-1), which is actually 65535 as unsigned.

    of course, this code produces an access violation because there is no elements 65535.

    for(unsigned short i = n_elements - 1; i >= 0; i--)
    {
    array = blah;
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice