Discussion:
Initialize int64?
(too old to reply)
Michael Wade
2008-03-16 19:51:49 UTC
Permalink
How does one initialize an __int64 variable without getting an overflow warning? I am trying
this...

static const unsigned __int64 Mask37 = 0x1fffffffffL;

Thanks,
Michael
Jason Cipriani
2008-03-16 20:00:27 UTC
Permalink
Post by Michael Wade
How does one initialize an __int64 variable without getting an overflow
warning? I am trying
this...
static const unsigned __int64 Mask37 = 0x1fffffffffL;
Use the suffix "i64":

static const unsigned __int64 Maxk37 = 0x1fffffffffi64;
Post by Michael Wade
Thanks,
Michael
Jason Cipriani
2008-03-16 20:05:01 UTC
Permalink
Post by Jason Cipriani
Post by Michael Wade
How does one initialize an __int64 variable without getting an overflow
warning? I am trying
this...
static const unsigned __int64 Mask37 = 0x1fffffffffL;
static const unsigned __int64 Maxk37 = 0x1fffffffffi64;
LL suffix also works, FYI. As far as what is "standard"... I don't see
either LL or i64 in C++03. But both work on Borland's compiler, and others,
at least.

Jason
Leo Siefert
2008-03-17 11:57:00 UTC
Permalink
Post by Jason Cipriani
LL suffix also works, FYI. As far as what is "standard"...
I don't see either LL or i64 in C++03.
It will be ll in C++0x, so that is probably the better choice.

- Leo
dhoke
2008-03-17 12:11:17 UTC
Permalink
Post by Leo Siefert
It will be ll in C++0x, so that is probably the better choice.
That seems nastily unreadable, using lower-case which in some fonts is not
readily distinguishable from one's... as in whatever font is used by my news
reader, reading your message.

Has the (sub-?)committee considered that?
Jason Cipriani
2008-03-17 16:01:39 UTC
Permalink
Post by dhoke
Post by Leo Siefert
It will be ll in C++0x, so that is probably the better choice.
Nice. Is it a bad sign that I'm pumped up about C++0x? I hope I'm not the
only one.
Post by dhoke
That seems nastily unreadable, using lower-case which in some fonts is not
readily distinguishable from one's... as in whatever font is used by my
news reader, reading your message.
Well you could do this:

#define A_GOOD_TYPE_TO_ASSIGN_LL_CONSTANT_TO __int64
#define LOWERCASE_I i
#define EQUALS =
#define ASSIGN_VALUE(t,n,v) t n EQUALS v
#define INTEGER_CONSTANT_WITH_SUFFIX(val,s) val##s
#define INTEGER_CONSTANT_WITH_LONGLONG_SUFFIX(val) \
INTEGER_CONSTANT_WITH_SUFFIX(val, ll) // <--- clear separation

ASSIGN_VALUE(A_GOOD_TYPE_TO_ASSIGN_LL_CONSTANT_TO,
LOWERCASE_I,
INTEGER_CONSTANT_WITH_LONGLONG_SUFFIX(0x01));

And that way the lowercase ll is clearly distinguishable from the rest of
the constant. This is the way I prefer as it is very readable and clearly
describes what is going on. :-)
Post by dhoke
Has the (sub-?)committee considered that?
Lowercase and uppercase both work, in the current standard, and in the draft
for the new one as well (you'll be able to use ll or LL, both must be same
case). See [2.13.1] in both.

Jason
Leo Siefert
2008-03-18 12:02:15 UTC
Permalink
Post by dhoke
Has the (sub-?)committee considered that?
LL and ll are equivalent in the standard. For programming and reading
programming forums I always use a font that makes the difference
between l and 1 visible. I did not mean to imply that lower case was
preferred - it's just slightly easier to type.

- Leo
Michael Wade
2008-05-15 06:15:27 UTC
Permalink
Thank you everyone for helping me with this. I sincerely appreciate it. It helped me alot.

And, btw, how did you all know that? I searched on the net, obviously not good enough, but didn't
see anything.

Anyway, thanks again.

Michael
Post by Michael Wade
How does one initialize an __int64 variable without getting an overflow warning? I am trying
this...
static const unsigned __int64 Mask37 = 0x1fffffffffL;
Thanks,
Michael
Leo Siefert
2008-05-15 11:46:11 UTC
Permalink
Post by Michael Wade
And, btw, how did you all know that?
ms-help://borland.bds5/devwin32/extendedintegertypes_xml.html

can be found by looking up __int8, __int16....Extended Integer Types
in the help index. Looking up __int64 directly does not help much, but
I found this by trying a few other nearby entries.

- Leo

Loading...