help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: const uint64_t initialization problem


From: Maxim Yegorushkin
Subject: Re: const uint64_t initialization problem
Date: 14 Dec 2006 00:51:30 -0800
User-agent: G2/1.0

Mike - EMAIL IGNORED wrote:

> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]