Unsigned types are DANGEROUS??

Discussion in 'C++' started by MikeP, Mar 14, 2011.

  1. MikeP

    MikeP Guest

    If you investigate the tcmalloc code (by Google), you will find the
    following warning:

    // NOTE: unsigned types are DANGEROUS in loops and other arithmetical
    // places. Use the signed types unless your variable represents a bit
    // pattern (eg a hash value) or you really need the extra bit. Do NOT
    // use 'unsigned' to express "this value should always be positive";
    // use assertions for this.

    Is it just their idiom? What's the problem with using unsigned ints in
    loops (it seems natural to do so)? Are C++ unsigned ints "broken"
    somehow?
    MikeP, Mar 14, 2011
    #1
    1. Advertising

  2. MikeP

    MikeP Guest

    Leigh Johnston wrote:
    > On 14/03/2011 14:44, MikeP wrote:
    >> If you investigate the tcmalloc code (by Google), you will find the
    >> following warning:
    >>
    >> // NOTE: unsigned types are DANGEROUS in loops and other arithmetical
    >> // places. Use the signed types unless your variable represents a bit
    >> // pattern (eg a hash value) or you really need the extra bit. Do NOT
    >> // use 'unsigned' to express "this value should always be positive";
    >> // use assertions for this.
    >>
    >> Is it just their idiom? What's the problem with using unsigned ints
    >> in loops (it seems natural to do so)? Are C++ unsigned ints "broken"
    >> somehow?

    >
    > One religious war at a time please.
    >
    > /Leigh


    Having newsgroup and reader problems... sorry for the duplicate(s).
    MikeP, Mar 14, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. b83503104
    Replies:
    1
    Views:
    3,487
    Eric Sosman
    Jun 21, 2004
  2. MikeP
    Replies:
    215
    Views:
    3,253
    werasm
    Mar 30, 2011
  3. Paul
    Replies:
    10
    Views:
    413
  4. pozz
    Replies:
    12
    Views:
    716
    Tim Rentsch
    Mar 20, 2011
  5. tim
    Replies:
    40
    Views:
    1,544
    Shao Miller
    Feb 1, 2012
Loading...

Share This Page