| View previous topic :: View next topic |
| Author |
Message |
Richard Cavell Guest
|
Posted: Sun Feb 27, 2005 12:13 pm Post subject: using uint64_t with GCC |
|
|
uint64_t i64_BitMask = (uint64_t) (1 << 33) - 1 ;
int a = (i64_BitMask >> 32);
printf ("BitMask %xn", a);
This produces ffffffff. I'm pretty sure, watching the stages in
debugging, that 1 << 33 is resolving to zero, since it's being shifted
off the MSB of a 32 bit integer.
I am in general having problems with uint64_t with GCC. In particular,
I can't send one to printf and get a sensible output. The shift
operators appear to only work with 32-bit integers. Also, if I have
intermediate steps, it always seems to want to truncate the output to
32-bits. Putting in casts to uint64_t sometimes fixes it, but not
always. What do I do?
(using XCode, Apple's stdint.h)
|
|
| Back to top |
|
 |
jacob navia Guest
|
Posted: Sun Feb 27, 2005 1:22 pm Post subject: Re: using uint64_t with GCC |
|
|
Richard Cavell wrote:
| Quote: |
uint64_t i64_BitMask = (uint64_t) (1 << 33) - 1 ;
|
The problem is that the expression
(1 << 33)
is calculated (as it should) in integer mode, i.e. 32 bits.
The result (zero) is *THEN* cast to uint64_t.
Fix:
uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;
jacob
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Sun Feb 27, 2005 2:55 pm Post subject: Re: using uint64_t with GCC |
|
|
jacob navia wrote:
=
| Quote: |
uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;
|
You have an unneeded cast there. The left-most cast serves no
purpose.
|
|
| Back to top |
|
 |
jacob navia Guest
|
Posted: Sun Feb 27, 2005 5:05 pm Post subject: Re: using uint64_t with GCC |
|
|
Ron Natalie wrote:
| Quote: | jacob navia wrote:
=
uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;
You have an unneeded cast there. The left-most cast serves no
purpose.
|
True.
uint64_t i64_BitMask = ((uint64_t)1 << 33) - 1 ;
is better.
Also good is
uint64_t i64_BitMask = (1LL << 33) - 1 ;
jacob
|
|
| Back to top |
|
 |
bachelor Guest
|
Posted: Sun Feb 27, 2005 5:35 pm Post subject: Re: using uint64_t with GCC |
|
|
i don't know why you need shifts, in some cases <bitset> is more
elegant IMHO
|
|
| Back to top |
|
 |
|