LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Gentoo
User Name
Password
Gentoo This forum is for the discussion of Gentoo Linux.

Notices


Reply
  Search this Thread
Old 11-21-2012, 01:35 AM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
gcc 64-bit 4 byte int


Is there a gcc flag I can use to tell it to use only 4 bytes for int on a 64-bit machine instead of 8 bytes?
 
Old 11-21-2012, 03:15 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
why do you need that? see here: http://crasseux.com/books/ctutorial/...variables.html and here: http://www.gnu.org/software/libc/man.../Integers.html

Last edited by pan64; 11-21-2012 at 03:18 AM. Reason: added info
 
Old 11-21-2012, 05:29 AM   #3
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Because using 8 bytes for an int is not needed if the same program will run fine with 4 bytes in a 32 bit distro. More of my ram is used than needed.
 
Old 11-21-2012, 05:55 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
What makes you think your int is 64bit?
If you need specific width, just use types from stdint.h, as suggested by pan64
 
Old 11-21-2012, 02:20 PM   #5
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
1) Is it only the long datatype that differs in size between 32 bit and 64 bit?

2) Then why does a 64 bit OS have higher memory requirements than the same OS in 32 bit?
 
Old 11-21-2012, 02:30 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by fakie_flip View Post
2) Then why does a 64 bit OS have higher memory requirements than the same OS in 32 bit?
1) X86 instructions in machine language vary in length from single byte instructions up to quite long (I'm not sure of the max). Average instruction length is larger in x86-64 than in 32-bit x86. That is partially balanced by some situations in which the compiler emits fewer instructions in x86-64 than in 32-bit for the same C code. But only partially balanced. On average, the same code compiles larger on x86-64 than 32-bit.

2) Pointers are twice as big in x86-64 as in x86. In many programs, a large fraction of the data is pointers (rather than basic types like int, char, double, etc.).

3) Considering a whole OS, rather than just a program, you should also consider that it is common to run a few 32-bit programs on a 64-bit OS, but you can't run any 64-bit programs on a 32-bit OS. A 32-bit program and 64-bit program running at the same time that use shared libraries compiled from the same source code, can't use the same binary shared libraries. So running more than one bit size of application means more memory is used by the whole system for shared libraries.

4) If I understand correctly (I'm not sure of this one) the exception handling for C++ for x86-64 is a totally redesigned system meant to minimize the run time overhead of having exception handling (the time it take to not have an exception) at the expense of both memory size and the execution time when you actually do have an exception.

Lots of minor reasons as well, such as a more layered page table structure in the kernel for mapping virtual addresses to physical addresses. (Compared to 32-bit non PAE, the page tables also have half capacity, so you need twice as many. 32-bit PAE has the same capacity per page table as x86-64).

Quote:
Originally Posted by fakie_flip View Post
Is there a gcc flag I can use to tell it to use only 4 bytes for int on a 64-bit machine instead of 8 bytes?
int is 4-bytes by default in gcc for x86-64.

There is a gcc switch -m32 that you can use on a 64-bit Linux (assuming 32-bit support is installed) to build your entire application as 32-bit, so pointers and longs are 32-bit just as on a 32-bit Linux.

If your application manipulates mainly pointers (rather than ints or doubles, etc.) and doesn't need more than 4GB per process. It may take significantly less memory and less CPU time run as a 32-bit application under a 64-bit OS than run as a 64-bit application.

It may seem bizarre to non programmers, but a lot of programs do manipulate pointers far more than actual data.

Most programs have no need to exceed the 4GB limit on a 32-bit program in a 64-bit OS. Even if the whole system has and needs far more than 4GB of physical ram, individual processes usually need less than 4GB of virtual ram each.

Last edited by johnsfine; 11-21-2012 at 02:44 PM.
 
1 members found this post helpful.
Old 11-23-2012, 11:32 PM   #7
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Ok, I knew a lot of that except the instruction code loaded into memory is larger. I'm asking if long is the only datatype that differs in default size (except pointers, you mentioned them already)?
 
Old 11-24-2012, 03:03 AM   #8
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
The only thing the standard says about this is that char <= short <= int <= long <= long long. Other than that, it's platform (CPU, OS, compiler) specific. If you want to write portable code, you should never assume anything about the size of the basic int types.
You may also find this interesting.

Last edited by millgates; 11-24-2012 at 03:04 AM.
 
Old 11-24-2012, 07:56 AM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by fakie_flip View Post
I'm asking if long is the only datatype that differs in default size (except pointers, you mentioned them already)?
There are types such as size_t and ptr_diff_t that (in ordinary architectures) need to be the same size as pointers even though they are not pointers. So in x86-64 those are also 8 bytes long.
 
  


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
[SOLVED] How to send SMBus 2-byte command (16-bit reg address)? auwerk Linux - Kernel 2 01-29-2012 08:01 PM
Compilation problem when downgrading from 64-bit gcc to 32-bit gcc huyhoang3673 Linux - Software 7 08-26-2009 11:31 AM
Bit shifting 6-byte value into a u64 ranthal Linux - Kernel 5 07-07-2009 09:26 PM
32/64 bit libs - FC6/gcc 4.1.1 -m32 picking up 64 bit library marier Fedora 0 04-24-2007 12:57 PM
64 bit CPU unsigned long int GodSendDeath Programming 8 03-29-2005 01:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Gentoo

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

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