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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-13-2008, 04:40 AM
|
#1
|
|
Member
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297
Rep:
|
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
|
|
|
|
03-13-2008, 05:21 AM
|
#2
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
I think a "long long" is 64 bit, no?
|
|
|
|
03-13-2008, 06:05 AM
|
#3
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Yes, regardless of the architecture being 32 or 64 bit.
Code:
main()
{
long long i64= (1LL<<62);
printf("%lld\n", i64);
}
|
|
|
|
03-13-2008, 06:57 AM
|
#4
|
|
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530
Rep: 
|
Quote:
Originally Posted by raven
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
|
|
|
|
03-13-2008, 07:09 AM
|
#5
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
Quote:
Originally Posted by Hko
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.
|
|
|
|
03-13-2008, 08:45 AM
|
#6
|
|
Member
Registered: Oct 2005
Posts: 970
Rep: 
|
Quote:
Originally Posted by jlliagre
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.
|
|
|
|
03-13-2008, 12:05 PM
|
#7
|
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
Quote:
Originally Posted by matthewg42
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. */
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:40 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|