gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > int64 with devkitARM

#121606 - KayH - Tue Mar 13, 2007 1:18 pm

I tried to use "unsigned long long" (u64). The definition of the variable was accepted, but the compilers error message tells me that the value is to big for a "long" integer (note: not "long long"). That means there is no u64 implemented, right? This is clear because the GBA is a 32bit sytem, but maybe the 64bit are emulated somehow.
I use instead a struct with two u32 (a high and a low part) and handle it myself.

How do you handle u64?

Thanks for your comments!
KaY

#121623 - tepples - Tue Mar 13, 2007 4:04 pm

When initializing a variable from a literal number, try putting "LL" (signed) or "ULL" (unsigned) after the number. For instance:
Code:
unsigned long long theNum = 123456789123456789ULL;
long long otherNum = -543215432154321LL;

_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#121654 - poslundc - Tue Mar 13, 2007 8:07 pm

Long longs have kind of a counter-intuitive behaviour in most compilers, it seems, where the binding to the type is very weak and the compiler will do everything it can to promote values away from it and back down to a regular int. As a result, you need to keep typecasting back to long long with 64-bit arithmetic far more frequently in order to maintain the precision.

Dan.

#121658 - Ant6n - Tue Mar 13, 2007 8:30 pm

troublemaker .. gets demoted

#121920 - KayH - Thu Mar 15, 2007 6:39 pm

Thank you for the input! Indeed it works with the "ULL", "LL" extension of the value. I was aware about "UL" and "L" extension, but this was outside my mind. ;-)

I hoped to simplify (and maybe to speed up) my code with the exchange from two u32 to one u64 variable. But now it seems to make more trouble on the long term. Although it work as expected, I decided to stay on my current solution.

Again thank you for your comments!
KaY

#121973 - Ant6n - Fri Mar 16, 2007 1:54 am

it makes most sense to store data in chunks that are considered to be a 'word' on the machine you are using. since gba/ds are 32 bit, they will operate on 32bit. so if you give it a 64 bit value, the compiler will internally expand it to be 32bit operations (only exception - multiplication, but apparently only in arm).

#122018 - KayH - Fri Mar 16, 2007 1:16 pm

You are right! I know this too.
But there were two ideas behind to try it out:
1) the compiler/lib would probably do the job like me or even better, then the game would not suffer but hopefully have a little benefit in speed
2) this was the most important thing here: the sourcecode would be a bit better two read.
Of course the result would be nearly identical. I haven't assumed to gain big benefit.

As already said: it was only a try and it failed. Thanks to the helpful comments given above.
(That's why I love this forum: one is able to learn alot and discuss with friendly and valuable people mostly without attitudes!)