LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2008, 04:40 AM   #1
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Rep: Reputation: 31
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
 
Old 03-13-2008, 05:21 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
I think a "long long" is 64 bit, no?
 
Old 03-13-2008, 06:05 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Yes, regardless of the architecture being 32 or 64 bit.

Code:
main()
{
        long long i64= (1LL<<62);
        printf("%lld\n", i64);
}
 
Old 03-13-2008, 06:57 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by raven View Post
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
 
Old 03-13-2008, 07:09 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by Hko View Post
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.
 
Old 03-13-2008, 08:45 AM   #6
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by jlliagre View Post
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.
 
Old 03-13-2008, 12:05 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by matthewg42 View Post
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. */
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't install amarok 64bit du eto missing provider of libpq.so.4()(64bit) Ossah Linux - Software 1 04-21-2007 09:23 PM
32bit Integer and 64bit Pointer Hoju2468 Programming 0 07-20-2006 09:44 AM
64bit Eval Issues...switched to 64bit OSS and WOW RedShirt SUSE / openSUSE 6 01-23-2006 09:07 PM
can 64bit processor run both 64bit and 32bit computers? DJOtaku Linux - General 4 09-08-2005 08:14 PM
Does 64Bit Linux have all 64Bit Packages UltimateLinux Linux - Distributions 5 02-19-2005 02:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration