Just to quickly address the "why don't we support unsigned ints?" question, 
most of the answers given were correct.

- Unsigned ints are not consistently implemented across languages
  - In particular, neither Python nor Java, two of the most widely-used 
languages, support them
  - Hacking in support makes for messy serialization/deserialization code, and 
you run into problems when you are actually using the high bit (i.e. does long 
have to all of a sudden become BigInteger in Java for correctness?)

- We noticed in practice that unsigned ints are almost NEVER used for arithmetic
  - They are most commonly used as unique identifiers
  - Sign is not important for using these as identifiers
  - If you really want the unsigned value, casting is a viable solution, if 
slightly annoying

My recommendations on this is generally:

1. Check -- do you actually NEED unsigned integers? Are you doing any 
arithmetic with them?
2. If the answer is actually yes, then cast them.

Cheers,
Mark

-----Original Message-----
From: Yingbo Miao [mailto:[email protected]] 
Sent: Tuesday, June 16, 2009 7:51 AM
To: [email protected]
Subject: Re: uint64_t

In C++, you can cast uint64_t to int64_t and cast back. Data won't be  
lost, since both are 64-bits. e.g.

     uint64_t ui = 0xFFFFFFFFFFFFFFFF;
     cout << "ui=" << ui << endl;    int64_t ii= ui;
     cout << "ii=" << ii << endl;
     uint64_t ui2= ii;
     cout << "ui2=" << ui2 << endl;

and the outputs are:
     ui=18446744073709551615
     ii=-1
     ui2=18446744073709551615



--Yingbo

On Jun 16, 2009, at 6:36 AM, Ephraim Dan wrote:

> We have some big numbers, that we use "unsigned long  
> long" (uint64_t) for in our code.
> Thrift apparently explicitly doesn't support unsigned integer types.
> What are we to do if we do, after all, need to transport such a  
> number using thrift?
>
> Thanks
> --edan

Reply via email to