Thread: signed/unsigned int

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Now since you have it as unsigned it creates problems by genrating random outputs.
    There's nothing random about it. Unsigned underflow wraps around to the largest value for the type. The problem is that the loop is infinite because an unsigned integer cannot hold a value less than 0 whereas a plain integer, which is signed, can. The behavior is well defined, so the following loop is incorrect:
    Code:
    for (unsigned i = n; i >= 0; i--)
    My best code is written with the delete key.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    Aha i didnt think of that, thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM