[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: const uint64_t initialization problem

**From**: |
Ulrich Eckhardt |

**Subject**: |
Re: const uint64_t initialization problem |

**Date**: |
Thu, 07 Dec 2006 19:54:18 +0100 |

**User-agent**: |
KNode/0.10.4 |

Mike - EMAIL IGNORED wrote:
>* On FC4 with g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8):*
>* *
>* unsigned long long mask = 0x003fffffffffffff;*
>* const uint64_t mask = 0x003fffffffffffff;*
>* const uint64_t mask = static_cast<uint64_t>(0x003fffffffffffff);*
>* *
>* all result in:*
>* *
>* error: integer constant is too large for 'long' type*
Try to explicitly say that it's a 'long long':
unsigned long long const foo = 0x0123456789abcdefull;
Note the 'ull' suffix for an unsigned long long.
There might be a way to construct a 64bit integer in stdint.h, where the
uint64_t also comes from, probably a macro. If you specifically want 64
bits you should use that.
>* I workaround with:*
>* *
>* const uint64_t mask = (0x003fffff << 32) | 0xffffffff;*
^^^^^^^^^^^^^^^^
You noticed it in your second posting, this pushes the bits out at the top.
Also, IIRC the argument for a shift operation must be smaller than the size
in bits, otherwise invoking undefined behaviour. There are compilers that
take this argument modulo the number of bits and those compilers are
standard-conformant! At least I seem to remember such a discussion
somewhere on the Usenet...
>* Is this as expected?*
Yes.
>* Is it fixed in a later version? *
Not a bug, nothing to fix.
Uli
--
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/