unsigned long long int 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
I workaround with:
const uint64_t mask = (0x003fffff << 32) | 0xffffffff;
Is this as expected? Is it fixed in a later version?
Thanks,
Mike.
Correction. I need:
const uint64_t mask =
((static_cast<uint64_t>(0x003fffff) << 32) | 0xffffffff;
Mike.
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/
MyClass::MyClass()
: mask_(0x003fffffffffffffull),
sign_(0x0080000000000000ull)
{
}
works, where without the 'ull' it failed.
BTW uint64_t is a typedef on my system.
Thanks for your help.
Mike.
> On FC4 with g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8):
>
> unsigned long long int 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
>
> I workaround with:
>
> const uint64_t mask = (0x003fffff << 32) | 0xffffffff;
>
> Is this as expected?
The workaround may not work as expected. The expected result of
(0x003fffff << 32) is int(0).
> Is it fixed in a later version?
You could use a suffix for your long constant as you know already, or
use a portable macro from <stdint.h>
/* Unsigned. */
# define UINT8_C(c) c
# define UINT16_C(c) c
# define UINT32_C(c) c ## U
# if __WORDSIZE == 64
# define UINT64_C(c) c ## UL
# else
# define UINT64_C(c) c ## ULL
# endif
http://www.opengroup.org/onlinepubs/000095399/basedefs/stdint.h.html#tag_13_48_03_04
> On FC4 with g++ (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8):
>
> unsigned long long int 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
>
> I workaround with:
>
> const uint64_t mask = (0x003fffff << 32) | 0xffffffff;
>
> Is this as expected?
The workaround may not work as expected. The expected result of
(0x003fffff << 32) is int(0).
> Is it fixed in a later version?
You could use a suffix for your long constant as you know already, or