Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Unsigned types are DANGEROUS??

Reply
Thread Tools

Unsigned types are DANGEROUS??

 
 
MikeP
Guest
Posts: n/a
 
      03-14-2011
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?



 
Reply With Quote
 
 
 
 
MikeP
Guest
Posts: n/a
 
      03-14-2011
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).


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(int) -> (unsigned) -> (int) or (unsigned) -> (int) -> (unsigned):I'll loose something? pozz C Programming 12 03-20-2011 11:32 PM
unsigned long to unsigned char ashtonn@gmail.com Python 1 06-01-2005 07:00 PM
comparing unsigned long and unsigned int sridhar C Programming 6 11-03-2004 03:52 AM
unsigned int const does not match const unsigned int Timo Freiberger C++ 3 10-30-2004 07:02 PM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments