LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Using 64bit integer (http://www.linuxquestions.org/questions/programming-9/using-64bit-integer-627709/)

raven 03-13-2008 05:40 AM

Using 64bit integer
 
Hello

Does anyopne know how to tell gcc (4.2) to use 64bit integers instead of 32bit? I have a program which gets an integer overflow (no, it's not bad code...) on a IA64 architecture and need to correct it.

Thanks

raven

matthewg42 03-13-2008 06:21 AM

I think a "long long" is 64 bit, no?

jlliagre 03-13-2008 07:05 AM

Yes, regardless of the architecture being 32 or 64 bit.

Code:

main()
{
        long long i64= (1LL<<62);
        printf("%lld\n", i64);
}


Hko 03-13-2008 07:57 AM

Quote:

Originally Posted by raven (Post 3087145)
Does anyopne know how to tell gcc (4.2) to use 64bit integers instead of 32bit? I have a program which gets an integer overflow (no, it's not bad code...) on a IA64 architecture and need to correct it.

Code:

/* size.c */
#include <stdio.h>
#include <limits.h>

int main()
{
    printf("Size of int is %d bits\n", 8*sizeof(int));
    printf("IN_MAX (signed) is %d\n", INT_MAX);
    return 0;
}

To my surprise it does not make any difference for vanilla int's.

On my 32-bit computer (running Ubuntu "Gutsy"):
Code:

bash$ gcc --version
gcc (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)

bash$ file size
size: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), not stripped

bash$ ./size
Size of int is 32 bits
IN_MAX (signed) is 2147483647

On my AMD64 PC (running Debian "Lenny"):
Code:

bash$ gcc --version
gcc (GCC) 4.2.3 20080114 (prerelease) (Debian 4.2.2-7)

bash$ file size
size: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.8, dynamically linked (uses shared libs), not stripped

bash$ ./size
Size of int is 32 bits
IN_MAX (signed) is 2147483647


jlliagre 03-13-2008 08:09 AM

Quote:

Originally Posted by Hko (Post 3087231)
To my surprise it does not make any difference for vanilla int's.

This is not to disrupt the huge amount of source code assuming an int is 32 bit long.
The LP64 model which keep the int as a 32 bit entity was agreed upon most Unix vendors around 1995.

dmail 03-13-2008 09:45 AM

Quote:

Originally Posted by jlliagre (Post 3087239)
This is not to disrupt the huge amount of source code assuming an int is 32 bit long.
The LP64 model which keep the int as a 32 bit entity was agreed upon most Unix vendors around 1995.

See 64-bit and Data Size Neutrality for these details.

osor 03-13-2008 01:05 PM

Quote:

Originally Posted by matthewg42 (Post 3087180)
I think a "long long" is 64 bit, no?

Technically, long long is at least 64 bits in width. Although on most implementations it really is 64 bits.

I think the safer way is to use
Code:

#include <stdint.h>

int64_t i64;
uint64_t ui64;
/* Etc. */



All times are GMT -5. The time now is 03:02 PM.