From owner-freebsd-questions@FreeBSD.ORG Mon May 25 12:00:38 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 465E11065694 for ; Mon, 25 May 2009 12:00:38 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from smtp.infracaninophile.co.uk (gate6.infracaninophile.co.uk [IPv6:2001:8b0:151:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 980818FC1B for ; Mon, 25 May 2009 12:00:37 +0000 (UTC) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost [IPv6:::1]) (authenticated bits=0) by smtp.infracaninophile.co.uk (8.14.3/8.14.3) with ESMTP id n4PC0SCB084922; Mon, 25 May 2009 13:00:30 +0100 (BST) (envelope-from m.seaman@infracaninophile.co.uk) X-DKIM: Sendmail DKIM Filter v2.8.2 smtp.infracaninophile.co.uk n4PC0SCB084922 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=infracaninophile.co.uk; s=200708; t=1243252830; bh=5B8gFr3y7cDJ+9IQyqydqRaknp/1ecVW0w90DXy/4pQ=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Cc:Content-Type:Date:From:In-Reply-To: Message-ID:Mime-Version:References:To; z=Message-ID:=20<4A1A8854.2010306@infracaninophile.co.uk>|Date:=20M on,=2025=20May=202009=2013:00:20=20+0100|From:=20Matthew=20Seaman= 20|Organization:=20Infracaninophi le|User-Agent:=20Thunderbird=202.0.0.21=20(X11/20090420)|MIME-Vers ion:=201.0|To:=20Shakil=20Khan=20|CC:=20free bsd-questions@freebsd.org|Subject:=20Re:=20why=20integer=20size=20 says=204=20bytes=20on=2064=20bit=20processor|References:=20<717ed9 590905250355o3f3b836bm9e2e5abee03d50b2@mail.gmail.com>|In-Reply-To :=20<717ed9590905250355o3f3b836bm9e2e5abee03d50b2@mail.gmail.com>| X-Enigmail-Version:=200.95.6|Content-Type:=20multipart/signed=3B=2 0micalg=3Dpgp-sha256=3B=0D=0A=20protocol=3D"application/pgp-signat ure"=3B=0D=0A=20boundary=3D"------------enig07E367EEFA40A5CA0A3D51 56"; b=cPyv+GY1TGsstHOb2ow+atYbN8PJF1RejsKQ0NGgvBrXjrHVPxHag8I0tFDQkXLKu 81UvTh5rD/KB57MkCXPKG1OUfKso/vVsssYxk9ORRnemPASTgJsPT7qvpjGxSOscFb H0w40GIezTTmOWCDXjsY7DHUOdH8pU6Gc5A/j00s= X-Authentication-Warning: happy-idiot-talk.infracaninophile.co.uk: Host localhost [IPv6:::1] claimed to be happy-idiot-talk.infracaninophile.co.uk Message-ID: <4A1A8854.2010306@infracaninophile.co.uk> Date: Mon, 25 May 2009 13:00:20 +0100 From: Matthew Seaman Organization: Infracaninophile User-Agent: Thunderbird 2.0.0.21 (X11/20090420) MIME-Version: 1.0 To: Shakil Khan References: <717ed9590905250355o3f3b836bm9e2e5abee03d50b2@mail.gmail.com> In-Reply-To: <717ed9590905250355o3f3b836bm9e2e5abee03d50b2@mail.gmail.com> X-Enigmail-Version: 0.95.6 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig07E367EEFA40A5CA0A3D5156" X-Virus-Scanned: clamav-milter 0.95.1 at happy-idiot-talk.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED,NO_RELAYS autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on happy-idiot-talk.infracaninophile.co.uk Cc: freebsd-questions@freebsd.org Subject: Re: why integer size says 4 bytes on 64 bit processor X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 May 2009 12:00:40 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig07E367EEFA40A5CA0A3D5156 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Shakil Khan wrote: > Pardon me if I am writing this mail to the wrong group as I am too new = to > BSD and programming stuff. You can redirect me to right group without > howling. By seeing some recent conversations(About the top status ;)) i= n > this group it made me nervous to ask for a silly question like this, bu= t it > intrigued my mind too much so thought to delve into it keeping aside my= > fear. If you're not sure which is the right list, then questions@.... is a good= place to start. I'd hope no one would fear to ask what they needed to know in = this list, or it will have become pretty useless for its intended function. =20 > I have a 64bit intel processor, Dual core machine and I have installed = 64 > bit Linux as well as FreeBSD and thought of seeing the size of integer.= On > both the platform my integer is showing 4 bytes which is 32 bit. I thou= ght > integer are the most basic of the data types and governs the architectu= re as > 32 bit or 64 bit, so why integer shows me 4bytes instead of 8. Does thi= s > means that even on 64 bit architecture we are limited to just 4GB of RA= M. Not at all. 'int' is just one of the basic types mandated by the various= C specifications over the years. There are 4 basic integer types -- toge= ther with their unsigned counterparts: char unsigned char --- usually 1 byte[*]. short unsigned short --- usually 2 bytes int unsigned --- usually 4 bytes long unsigned long --- nowadays usually 8 bytes Now, the C standards only require that the lengths of these types fulfil the following condition: short <=3D int <=3D long and there are some older CPU architectures where short and int are 2 byte= s and long is 4 bytes, but those are exceedingly rare nowadays and you won'= t run into anything like that unless you work on embedded systems. In general the sizes above are what pretty much all current CPUs since ab= out 2000 have supported -- mostly because that's what the Intel x86 series us= ed. Before then there were quite a few CPUs where 'long' was 4 bytes, but tho= se sizes were otherwise about the same. However, it's not the size of 'int' which is the important thing. It's the size of pointers. The big deal with 64bit vs 32bit architectures is having registers of the= appropriate length that you can do 64bit integer operations natively. Th= is particularly applies to memory address manipulation. In principle you ca= n make a composite integer type of any length by stringing together as many= =20 shorter types as you want, but in practice that's too inefficient for mos= t purposes, especially anything as fundamental as memory addressing. So poi= nters are generally no longer than the widest hardware registers on the CPU. H= ence the length of pointers (memory addresses) is the fundamental distinction.= On a 32bit architecture, pointers are 4bytes long and can address up to=20 4294967296 bytes (4GiB) of RAM. On a 64bit machines pointers are 8bytes l= ong and can address 18446744073709551616 bytes (16EiB) of RAM. The Intel Cor= e 2 Duo is capable of running in either 32 or 64 bit mode. This C snippet wi= ll show you how long some important types are on your system: #include int main (int argc, char *argv) { printf( "int:\t%d\nlong:\t%d\npointer:\t%d\n", sizeof(int), sizeof(long), sizeof(void*) ); } Cheers, Matthew [*] char can sometimes be an unsigned quantity, in which case there should be a 'signed char' equivalent. --=20 Dr Matthew J Seaman MA, D.Phil. 7 Priory Courtyard Flat 3 PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate Kent, CT11 9PW --------------enig07E367EEFA40A5CA0A3D5156 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.11 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEAREIAAYFAkoaiFwACgkQ8Mjk52CukIyBKwCglEg4ZT44pgxgA+Bbd1nk7mAO xsoAnjaTbhUKUMpcZn2B1h3bae8mLftF =hUHQ -----END PGP SIGNATURE----- --------------enig07E367EEFA40A5CA0A3D5156--