• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

64-bit integers in C

Chaotic42

Lifer
Edit: Ok, I'm going to change this instead of making a new thread.

Is there a way to allow access to 64-bit integers in C? I need to manipulate numbers larger than 2147483647.
 
I had a look. It worked for me with unsigned long int for the type, but not unsigned long long int. What did you figure out?
 
how much larger than 2147483647? unsigned ints can handle twice that.

Edit: Also, declaring a variable as:

long long var = 6000000000;

seems to work as well.
 
Originally posted by: Chaotic42
Originally posted by: BingBongWongFooey
Yep, long long is guaranteed to be at least 64 bits, however you need to make sure and compile your code as c99, not c89/90.

How do I do that?

gcc -std=c99 or -std=gnu99 (c99 w/ gnu extensions)

You could also use a library like glib (guint64 / gint64) or sdl (Uint64 / Sint64), although those might need c99 mode turned on anyways. Not sure.
 
Ok, I included stdint.h, compiled with -lm and -std=gnu99, changed the variable type from unsigned long long int to uint_64t, and it still doesn't like numbers larger than 2^31-1.

Here's the top part of the code:
 
Originally posted by: Chaotic42
Ok, I included stdint.h, compiled with -lm and -std=gnu99, changed the variable type from unsigned long long int to uint_64t, and it still doesn't like numbers larger than 2^31-1.

Here's the top part of the code:

What do you mean, "it still doesn't like"? Compiler error? Run-time error?
 
Originally posted by: AgentEL
Originally posted by: Chaotic42
Ok, I included stdint.h, compiled with -lm and -std=gnu99, changed the variable type from unsigned long long int to uint_64t, and it still doesn't like numbers larger than 2^31-1.

Here's the top part of the code:

What do you mean, "it still doesn't like"? Compiler error? Run-time error?

I mean it caps the numbers at 2^31-1.

If I put in 999999999999999999999999999999 it caps it at 2147483647.
 
Are you using literal numbers in your assignments? They need the LLU(or maybe it's ULL) identifier on the end or they automatically get converted to another datatype (ints I think).

Like this

unsigned long long int total = 99999999999999ULL + 8888888888888ULL
 
Back
Top